mirror of
https://github.com/internetee/registry.git
synced 2025-08-26 02:53:31 +02:00
Merge branch 'story/109070142-nameservers' into staging
This commit is contained in:
commit
58799611c5
5 changed files with 58 additions and 29 deletions
|
@ -147,8 +147,8 @@ module Depp
|
||||||
data.css('hostAttr').each_with_index do |x, i|
|
data.css('hostAttr').each_with_index do |x, i|
|
||||||
ret[:nameservers_attributes][i] = {
|
ret[:nameservers_attributes][i] = {
|
||||||
hostname: x.css('hostName').text,
|
hostname: x.css('hostName').text,
|
||||||
ipv4: x.css('hostAddr[ip="v4"]').text,
|
ipv4: Array(x.css('hostAddr[ip="v4"]')).map(&:text).join(','),
|
||||||
ipv6: x.css('hostAddr[ip="v6"]').text
|
ipv6: Array(x.css('hostAddr[ip="v6"]')).map(&:text).join(',')
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -252,8 +252,13 @@ module Depp
|
||||||
|
|
||||||
host_attr = []
|
host_attr = []
|
||||||
host_attr << { hostName: { value: v['hostname'] } }
|
host_attr << { hostName: { value: v['hostname'] } }
|
||||||
host_attr << { hostAddr: { value: v['ipv4'], attrs: { ip: 'v4' } } } if v['ipv4'].present?
|
v['ipv4'].to_s.split(",").each do |ip|
|
||||||
host_attr << { hostAddr: { value: v['ipv6'], attrs: { ip: 'v6' } } } if v['ipv6'].present?
|
host_attr << { hostAddr: { value: ip, attrs: { ip: 'v4' } } }
|
||||||
|
end if v['ipv4'].present?
|
||||||
|
|
||||||
|
v['ipv6'].to_s.split(",").each do |ip|
|
||||||
|
host_attr << { hostAddr: { value: ip, attrs: { ip: 'v6' } } }
|
||||||
|
end if v['ipv6'].present?
|
||||||
|
|
||||||
ret << { hostAttr: host_attr }
|
ret << { hostAttr: host_attr }
|
||||||
end
|
end
|
||||||
|
|
|
@ -201,7 +201,7 @@ class Epp::Domain < Domain
|
||||||
if action == 'rem'
|
if action == 'rem'
|
||||||
to_destroy = []
|
to_destroy = []
|
||||||
ns_list.each do |ns_attrs|
|
ns_list.each do |ns_attrs|
|
||||||
nameserver = nameservers.where(ns_attrs).try(:first)
|
nameserver = nameservers.find_by_hash_params(ns_attrs).first
|
||||||
if nameserver.blank?
|
if nameserver.blank?
|
||||||
add_epp_error('2303', 'hostAttr', ns_attrs[:hostname], [:nameservers, :not_found])
|
add_epp_error('2303', 'hostAttr', ns_attrs[:hostname], [:nameservers, :not_found])
|
||||||
else
|
else
|
||||||
|
@ -223,8 +223,8 @@ class Epp::Domain < Domain
|
||||||
frame.css('hostAttr').each do |x|
|
frame.css('hostAttr').each do |x|
|
||||||
host_attr = {
|
host_attr = {
|
||||||
hostname: x.css('hostName').first.try(:text),
|
hostname: x.css('hostName').first.try(:text),
|
||||||
ipv4: x.css('hostAddr[ip="v4"]').first.try(:text),
|
ipv4: x.css('hostAddr[ip="v4"]').map(&:text).compact,
|
||||||
ipv6: x.css('hostAddr[ip="v6"]').first.try(:text)
|
ipv6: x.css('hostAddr[ip="v6"]').map(&:text).compact
|
||||||
}
|
}
|
||||||
|
|
||||||
res << host_attr.delete_if { |_k, v| v.blank? }
|
res << host_attr.delete_if { |_k, v| v.blank? }
|
||||||
|
@ -415,7 +415,7 @@ class Epp::Domain < Domain
|
||||||
{ id: inf_data.id, _destroy: 1 }
|
{ id: inf_data.id, _destroy: 1 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_statuses_attrs(frame, action)
|
def domain_statuses_attrs(frame, action)
|
||||||
status_list = domain_status_list_from(frame)
|
status_list = domain_status_list_from(frame)
|
||||||
if action == 'rem'
|
if action == 'rem'
|
||||||
|
|
|
@ -9,8 +9,10 @@ class Nameserver < ActiveRecord::Base
|
||||||
|
|
||||||
# rubocop: disable Metrics/LineLength
|
# rubocop: disable Metrics/LineLength
|
||||||
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
|
||||||
validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_blank: true }
|
# validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_blank: true }
|
||||||
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
# validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
|
||||||
|
validate :val_ipv4
|
||||||
|
validate :val_ipv6
|
||||||
# rubocop: enable Metrics/LineLength
|
# rubocop: enable Metrics/LineLength
|
||||||
|
|
||||||
before_validation :normalize_attributes
|
before_validation :normalize_attributes
|
||||||
|
@ -19,30 +21,43 @@ class Nameserver < ActiveRecord::Base
|
||||||
|
|
||||||
def epp_code_map
|
def epp_code_map
|
||||||
{
|
{
|
||||||
'2302' => [
|
'2302' => [
|
||||||
[:hostname, :taken, { value: { obj: 'hostAttr', val: hostname } }]
|
[:hostname, :taken, { value: { obj: 'hostAttr', val: hostname } }]
|
||||||
],
|
],
|
||||||
'2005' => [
|
'2005' => [
|
||||||
[:hostname, :invalid, { value: { obj: 'hostAttr', val: hostname } }],
|
[:hostname, :invalid, { value: { obj: 'hostAttr', val: hostname } }],
|
||||||
[:ipv4, :invalid, { value: { obj: 'hostAddr', val: ipv4 } }],
|
[:ipv4, :invalid, { value: { obj: 'hostAddr', val: ipv4 } }],
|
||||||
[:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }]
|
[:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }]
|
||||||
],
|
],
|
||||||
'2306' => [
|
'2306' => [
|
||||||
[:ipv4, :blank]
|
[:ipv4, :blank]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_attributes
|
def normalize_attributes
|
||||||
self.hostname = hostname.try(:strip).try(:downcase)
|
self.hostname = hostname.try(:strip).try(:downcase)
|
||||||
self.ipv4 = ipv4.try(:strip)
|
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
|
||||||
self.ipv6 = ipv6.try(:strip).try(:upcase)
|
self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
hostname
|
hostname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def val_ipv4
|
||||||
|
regexp = /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/
|
||||||
|
ipv4.to_a.each do |ip|
|
||||||
|
errors.add(:ipv4, :invalid) unless ip =~ regexp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def val_ipv6
|
||||||
|
regexp = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/
|
||||||
|
ipv6.to_a.each do |ip|
|
||||||
|
errors.add(:ipv6, :invalid) unless ip =~ regexp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def replace_hostname_ends(domains, old_end, new_end)
|
def replace_hostname_ends(domains, old_end, new_end)
|
||||||
domains = domains.where('EXISTS(
|
domains = domains.where('EXISTS(
|
||||||
|
@ -58,8 +73,8 @@ class Nameserver < ActiveRecord::Base
|
||||||
|
|
||||||
hn = ns.hostname.chomp(old_end)
|
hn = ns.hostname.chomp(old_end)
|
||||||
ns_attrs[:nameservers_attributes] << {
|
ns_attrs[:nameservers_attributes] << {
|
||||||
id: ns.id,
|
id: ns.id,
|
||||||
hostname: "#{hn}#{new_end}"
|
hostname: "#{hn}#{new_end}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -74,5 +89,14 @@ class Nameserver < ActiveRecord::Base
|
||||||
return 'replaced_all' if prc == 1.0
|
return 'replaced_all' if prc == 1.0
|
||||||
'replaced_some'
|
'replaced_some'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_by_hash_params params
|
||||||
|
params = params.with_indifferent_access
|
||||||
|
rel = all
|
||||||
|
rel = rel.where(hostname: params[:hostname])
|
||||||
|
# rel = rel.where(hostname: params[:hostname]) if params[:ipv4]
|
||||||
|
# ignoring ips
|
||||||
|
rel
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,8 +27,8 @@ xml.epp_head do
|
||||||
@nameservers.each do |x|
|
@nameservers.each do |x|
|
||||||
xml.tag!('domain:hostAttr') do
|
xml.tag!('domain:hostAttr') do
|
||||||
xml.tag!('domain:hostName', x.hostname)
|
xml.tag!('domain:hostName', x.hostname)
|
||||||
xml.tag!('domain:hostAddr', x.ipv4, 'ip' => 'v4') if x.ipv4.present?
|
x.ipv4.each{|ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v4') } if x.ipv4.present?
|
||||||
xml.tag!('domain:hostAddr', x.ipv6, 'ip' => 'v6') if x.ipv6.present?
|
x.ipv6.each{|ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v6') } if x.ipv6.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
= label_tag "domain_nameservers_attributes_#{k}_ipv4", t(:ipv4)
|
= label_tag "domain_nameservers_attributes_#{k}_ipv4", t(:ipv4)
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= text_field_tag "domain[nameservers_attributes][#{k}][ipv4]", v['ipv4'],
|
= text_field_tag "domain[nameservers_attributes][#{k}][ipv4]", v['ipv4'],
|
||||||
class: 'form-control', ipv4: true
|
class: 'form-control'#, ipv4: true
|
||||||
.form-group
|
.form-group
|
||||||
.col-md-3.control-label
|
.col-md-3.control-label
|
||||||
= label_tag "domain_nameservers_attributes_#{k}_ipv6", t(:ipv6)
|
= label_tag "domain_nameservers_attributes_#{k}_ipv6", t(:ipv6)
|
||||||
.col-md-7
|
.col-md-7
|
||||||
= text_field_tag "domain[nameservers_attributes][#{k}][ipv6]", v['ipv6'],
|
= text_field_tag "domain[nameservers_attributes][#{k}][ipv6]", v['ipv6'],
|
||||||
class: 'form-control', ipv6: true
|
class: 'form-control'#, ipv6: true
|
||||||
:coffee
|
:coffee
|
||||||
$("#nameservers").nestedAttributes
|
$("#nameservers").nestedAttributes
|
||||||
bindAddTo: $(".add-nameserver")
|
bindAddTo: $(".add-nameserver")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue