diff --git a/app/models/depp/domain.rb b/app/models/depp/domain.rb index 05c1698fc..fd0e71e9b 100644 --- a/app/models/depp/domain.rb +++ b/app/models/depp/domain.rb @@ -147,8 +147,8 @@ module Depp data.css('hostAttr').each_with_index do |x, i| ret[:nameservers_attributes][i] = { hostname: x.css('hostName').text, - ipv4: x.css('hostAddr[ip="v4"]').text, - ipv6: x.css('hostAddr[ip="v6"]').text + ipv4: Array(x.css('hostAddr[ip="v4"]')).map(&:text).join(','), + ipv6: Array(x.css('hostAddr[ip="v6"]')).map(&:text).join(',') } end @@ -252,8 +252,13 @@ module Depp host_attr = [] host_attr << { hostName: { value: v['hostname'] } } - host_attr << { hostAddr: { value: v['ipv4'], attrs: { ip: 'v4' } } } if v['ipv4'].present? - host_attr << { hostAddr: { value: v['ipv6'], attrs: { ip: 'v6' } } } if v['ipv6'].present? + v['ipv4'].to_s.split(",").each do |ip| + 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 } end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 17bb5915d..613c57115 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -201,7 +201,7 @@ class Epp::Domain < Domain if action == 'rem' to_destroy = [] 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? add_epp_error('2303', 'hostAttr', ns_attrs[:hostname], [:nameservers, :not_found]) else @@ -223,8 +223,8 @@ class Epp::Domain < Domain frame.css('hostAttr').each do |x| host_attr = { hostname: x.css('hostName').first.try(:text), - ipv4: x.css('hostAddr[ip="v4"]').first.try(:text), - ipv6: x.css('hostAddr[ip="v6"]').first.try(:text) + ipv4: x.css('hostAddr[ip="v4"]').map(&:text).compact, + ipv6: x.css('hostAddr[ip="v6"]').map(&:text).compact } res << host_attr.delete_if { |_k, v| v.blank? } @@ -415,7 +415,7 @@ class Epp::Domain < Domain { id: inf_data.id, _destroy: 1 } end end - + def domain_statuses_attrs(frame, action) status_list = domain_status_list_from(frame) if action == 'rem' diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 6206a4f16..ccedf0880 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -9,8 +9,10 @@ class Nameserver < ActiveRecord::Base # 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 :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 :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 } + validate :val_ipv4 + validate :val_ipv6 # rubocop: enable Metrics/LineLength before_validation :normalize_attributes @@ -19,30 +21,43 @@ class Nameserver < ActiveRecord::Base def epp_code_map { - '2302' => [ - [:hostname, :taken, { value: { obj: 'hostAttr', val: hostname } }] - ], - '2005' => [ - [:hostname, :invalid, { value: { obj: 'hostAttr', val: hostname } }], - [:ipv4, :invalid, { value: { obj: 'hostAddr', val: ipv4 } }], - [:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }] - ], - '2306' => [ - [:ipv4, :blank] - ] + '2302' => [ + [:hostname, :taken, { value: { obj: 'hostAttr', val: hostname } }] + ], + '2005' => [ + [:hostname, :invalid, { value: { obj: 'hostAttr', val: hostname } }], + [:ipv4, :invalid, { value: { obj: 'hostAddr', val: ipv4 } }], + [:ipv6, :invalid, { value: { obj: 'hostAddr', val: ipv6 } }] + ], + '2306' => [ + [:ipv4, :blank] + ] } end def normalize_attributes self.hostname = hostname.try(:strip).try(:downcase) - self.ipv4 = ipv4.try(:strip) - self.ipv6 = ipv6.try(:strip).try(:upcase) + self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip) + self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase) end def to_s hostname 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 def replace_hostname_ends(domains, old_end, new_end) domains = domains.where('EXISTS( @@ -58,8 +73,8 @@ class Nameserver < ActiveRecord::Base hn = ns.hostname.chomp(old_end) ns_attrs[:nameservers_attributes] << { - id: ns.id, - hostname: "#{hn}#{new_end}" + id: ns.id, + hostname: "#{hn}#{new_end}" } end @@ -74,5 +89,14 @@ class Nameserver < ActiveRecord::Base return 'replaced_all' if prc == 1.0 'replaced_some' 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 diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index f89fcd168..9e1779921 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -27,8 +27,8 @@ xml.epp_head do @nameservers.each do |x| xml.tag!('domain:hostAttr') do xml.tag!('domain:hostName', x.hostname) - xml.tag!('domain:hostAddr', x.ipv4, 'ip' => 'v4') if x.ipv4.present? - xml.tag!('domain:hostAddr', x.ipv6, 'ip' => 'v6') if x.ipv6.present? + x.ipv4.each{|ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v4') } if x.ipv4.present? + x.ipv6.each{|ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v6') } if x.ipv6.present? end end end diff --git a/app/views/registrar/domains/form_partials/_nameservers.haml b/app/views/registrar/domains/form_partials/_nameservers.haml index 177d164f0..557d28987 100644 --- a/app/views/registrar/domains/form_partials/_nameservers.haml +++ b/app/views/registrar/domains/form_partials/_nameservers.haml @@ -18,13 +18,13 @@ = label_tag "domain_nameservers_attributes_#{k}_ipv4", t(:ipv4) .col-md-7 = text_field_tag "domain[nameservers_attributes][#{k}][ipv4]", v['ipv4'], - class: 'form-control', ipv4: true + class: 'form-control'#, ipv4: true .form-group .col-md-3.control-label = label_tag "domain_nameservers_attributes_#{k}_ipv6", t(:ipv6) .col-md-7 = text_field_tag "domain[nameservers_attributes][#{k}][ipv6]", v['ipv6'], - class: 'form-control', ipv6: true + class: 'form-control'#, ipv6: true :coffee $("#nameservers").nestedAttributes bindAddTo: $(".add-nameserver") diff --git a/db/migrate/20151130175654_nameservers_i_ps_are_arrays.rb b/db/migrate/20151130175654_nameservers_i_ps_are_arrays.rb new file mode 100644 index 000000000..4e00709a8 --- /dev/null +++ b/db/migrate/20151130175654_nameservers_i_ps_are_arrays.rb @@ -0,0 +1,6 @@ +class NameserversIPsAreArrays < ActiveRecord::Migration + def change + change_column :nameservers, :ipv6, "varchar[] USING (string_to_array(ipv6, ','))", default: [] + change_column :nameservers, :ipv4, "varchar[] USING (string_to_array(ipv4, ','))", default: [] + end +end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 1573848f1..28786d278 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -272,12 +272,12 @@ namespace :import do x.object_registry.try(:registrar).try(:name), x.object.try(:registrar).try(:name) ? x.object.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name), x.id, - [x.street1.try(:strip), x.street2.try(:strip), x.street3.try(:strip)].join("\n"), + [x.street1.try(:strip), x.street2.try(:strip), x.street3.try(:strip)].compact.join(", "), x.city.try(:strip), x.postalcode.try(:strip), x.stateorprovince.try(:strip), x.country.try(:strip), - [x.object_state.try(:name)|| Contact::OK] + [x.object_state.try(:name), Contact::OK].compact ] if contacts.size % 10000 == 0 @@ -471,17 +471,20 @@ namespace :import do nsset = x.nsset nsset.hosts.each do |host| ip_maps = host.host_ipaddr_maps - ips = {} + ips = { + ipv4: [], + ipv6: [], + } ip_maps.each do |ip_map| next unless ip_map.ipaddr - ips[:ipv4] = ip_map.ipaddr.to_s if ip_map.ipaddr.ipv4? - ips[:ipv6] = ip_map.ipaddr.to_s if ip_map.ipaddr.ipv6? - end if ip_maps.any? + ips[:ipv4] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv4? + ips[:ipv6] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv6? + end nameservers << [ host.fqdn.try(:strip), - ips[:ipv4].try(:strip), - ips[:ipv6].try(:strip), + ips[:ipv4], + ips[:ipv6], x.object_registry.try(:registrar).try(:name), x.object.try(:registrar).try(:name) ? x.object.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name), x.id, diff --git a/lib/tasks/zonefile.rake b/lib/tasks/zonefile.rake index 5cec28cc3..31a6a1316 100644 --- a/lib/tasks/zonefile.rake +++ b/lib/tasks/zonefile.rake @@ -72,7 +72,7 @@ namespace :zonefile do WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter AND ns.hostname LIKE '%.' || d.name AND d.name <> i_origin - AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> '' + AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> '{}' AND NOT ('{serverHold,clientHold}' && d.statuses) ), chr(10) ) INTO tmp_var; @@ -92,7 +92,7 @@ namespace :zonefile do WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter AND ns.hostname LIKE '%.' || d.name AND d.name <> i_origin - AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> '' + AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> '{}' AND NOT ('{serverHold,clientHold}' && d.statuses) ), chr(10) ) INTO tmp_var;