1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2025-07-01 22:30:19 +02:00

helpers: refactor for simple functions

This commit is contained in:
cn
2018-02-03 21:40:44 +01:00
parent 9195d40344
commit acf3d7ed74
2 changed files with 27 additions and 20 deletions

23
lib/dyndnsd/helper.rb Normal file
View File

@ -0,0 +1,23 @@
require 'ipaddr'
module Dyndnsd
class Helper
def self.is_fqdn_valid?(hostname, domain)
return false if hostname.length < domain.length + 2
return false if not hostname.end_with?(domain)
name = hostname.chomp(domain)
return false if not name.match(/^[a-zA-Z0-9_-]+\.$/)
true
end
def self.is_ip_valid?(ip)
begin
IPAddr.new(ip)
return true
rescue ArgumentError
return false
end
end
end
end