Merge pull request #13 from internetee/staging

Staging
This commit is contained in:
Timo Võhmar 2015-11-30 23:13:18 +02:00
commit 807cdef9b5
8 changed files with 77 additions and 39 deletions

View file

@ -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

View file

@ -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? }

View file

@ -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
@ -35,14 +37,27 @@ class Nameserver < ActiveRecord::Base
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(
@ -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

View file

@ -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

View file

@ -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")

View file

@ -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

View file

@ -272,12 +272,12 @@ namespace :import do
x.object_registry.try(:registrar).try(:name), 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.object.try(:registrar).try(:name) ? x.object.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name),
x.id, 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.city.try(:strip),
x.postalcode.try(:strip), x.postalcode.try(:strip),
x.stateorprovince.try(:strip), x.stateorprovince.try(:strip),
x.country.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 if contacts.size % 10000 == 0
@ -471,17 +471,20 @@ namespace :import do
nsset = x.nsset nsset = x.nsset
nsset.hosts.each do |host| nsset.hosts.each do |host|
ip_maps = host.host_ipaddr_maps ip_maps = host.host_ipaddr_maps
ips = {} ips = {
ipv4: [],
ipv6: [],
}
ip_maps.each do |ip_map| ip_maps.each do |ip_map|
next unless ip_map.ipaddr next unless ip_map.ipaddr
ips[:ipv4] = ip_map.ipaddr.to_s if ip_map.ipaddr.ipv4? ips[:ipv4] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv4?
ips[:ipv6] = ip_map.ipaddr.to_s if ip_map.ipaddr.ipv6? ips[:ipv6] << ip_map.ipaddr.to_s.strip if ip_map.ipaddr.ipv6?
end if ip_maps.any? end
nameservers << [ nameservers << [
host.fqdn.try(:strip), host.fqdn.try(:strip),
ips[:ipv4].try(:strip), ips[:ipv4],
ips[:ipv6].try(:strip), ips[:ipv6],
x.object_registry.try(:registrar).try(:name), 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.object.try(:registrar).try(:name) ? x.object.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name),
x.id, x.id,

View file

@ -72,7 +72,7 @@ namespace :zonefile do
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
AND ns.hostname LIKE '%.' || d.name AND ns.hostname LIKE '%.' || d.name
AND d.name <> i_origin 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) AND NOT ('{serverHold,clientHold}' && d.statuses)
), chr(10) ), chr(10)
) INTO tmp_var; ) INTO tmp_var;
@ -92,7 +92,7 @@ namespace :zonefile do
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
AND ns.hostname LIKE '%.' || d.name AND ns.hostname LIKE '%.' || d.name
AND d.name <> i_origin 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) AND NOT ('{serverHold,clientHold}' && d.statuses)
), chr(10) ), chr(10)
) INTO tmp_var; ) INTO tmp_var;