Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hostnames in the allowed_ips list - good for DynDNS. #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/turnout/maintenance_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down