mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 03:58:27 +02:00
parent
cfec74f9f8
commit
45064b9392
2 changed files with 19 additions and 10 deletions
2
.reek
2
.reek
|
@ -1136,7 +1136,5 @@ UncommunicativeParameterName:
|
|||
- Dnskey#int_to_hex
|
||||
UncommunicativeMethodName:
|
||||
exclude:
|
||||
- Nameserver#val_ipv4
|
||||
- Nameserver#val_ipv6
|
||||
- Soap::Arireg#country_code_3
|
||||
- WhiteIp#validate_ipv4_and_ipv6
|
||||
|
|
|
@ -7,12 +7,25 @@ class Nameserver < ActiveRecord::Base
|
|||
*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]
|
||||
*[A-Za-z0-9])\z/x
|
||||
|
||||
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/x
|
||||
|
||||
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]))/x
|
||||
|
||||
belongs_to :domain, required: true
|
||||
|
||||
validates :hostname, presence: true
|
||||
validates :hostname, format: { with: HOSTNAME_REGEXP }, allow_blank: true
|
||||
validate :val_ipv4
|
||||
validate :val_ipv6
|
||||
validate :validate_ipv4_format
|
||||
validate :validate_ipv6_format
|
||||
validate :require_ip, if: :glue_record_required?
|
||||
|
||||
before_validation :normalize_attributes
|
||||
|
@ -90,17 +103,15 @@ class Nameserver < ActiveRecord::Base
|
|||
errors.add(:hostname, :invalid) if hostname =~ regexp
|
||||
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/
|
||||
def validate_ipv4_format
|
||||
ipv4.to_a.each do |ip|
|
||||
errors.add(:ipv4, :invalid) unless ip =~ regexp
|
||||
errors.add(:ipv4, :invalid) unless ip =~ IPV4_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]))/
|
||||
def validate_ipv6_format
|
||||
ipv6.to_a.each do |ip|
|
||||
errors.add(:ipv6, :invalid) unless ip =~ regexp
|
||||
errors.add(:ipv6, :invalid) unless ip =~ IPV6_REGEXP
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue