From ca0c3dda7d7b5fdedb75d73dd69d8e86470ab9b6 Mon Sep 17 00:00:00 2001 From: Jarek Jurasz Date: Mon, 15 May 2017 15:45:00 +0200 Subject: [PATCH] Allow hostnames in the allowed_ips list - good for DynDNS. --- lib/turnout/maintenance_file.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/turnout/maintenance_file.rb b/lib/turnout/maintenance_file.rb index 29055e2..140e6f2 100644 --- a/lib/turnout/maintenance_file.rb +++ b/lib/turnout/maintenance_file.rb @@ -95,7 +95,18 @@ def allowed_paths=(paths) # Splits strings on commas for easier importing of environment variables def allowed_ips=(ips) - ips = ips.to_s.split(',') if ips.is_a? String + ips = ips.to_s.split(/\s*,\s*/) if ips.is_a? String + # allow hostnames + ips = ips.map do |host| + next host if host =~ IPAddr::RE_IPV4ADDRLIKE + next host if host =~ IPAddr::RE_IPV6ADDRLIKE_FULL + next host if host =~ IPAddr::RE_IPV6ADDRLIKE_COMPRESSED + # DNS lookup pro request (cached by OS), works with DynDNS + hostname, aliases, family, *address_list = Socket.gethostbyname(host) + address_list.map do |addr| + ip = IPAddr::ntop(addr) + end + end.flatten @allowed_ips = ips end