mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Move some functions from ipa-server-install into installutils
We will need these functions in the new upcoming ipa-dns-install command.
This commit is contained in:
parent
5f5eb2fe13
commit
d53df67c95
@ -268,59 +268,6 @@ def resolve_host(host_name):
|
||||
print "Unable to lookup the IP address of the provided host"
|
||||
return ip
|
||||
|
||||
def verify_ip_address(ip):
|
||||
is_ok = True
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, ip)
|
||||
except:
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, ip)
|
||||
except:
|
||||
print "Unable to verify IP address"
|
||||
is_ok = False
|
||||
return is_ok
|
||||
|
||||
def read_ip_address(host_name):
|
||||
while True:
|
||||
ip = user_input("Please provide the IP address to be used for this host name", allow_empty = False)
|
||||
|
||||
if ip == "127.0.0.1" or ip == "::1":
|
||||
print "The IPA Server can't use localhost as a valid IP"
|
||||
continue
|
||||
|
||||
if not verify_ip_address(ip):
|
||||
continue
|
||||
|
||||
print "Adding ["+ip+" "+host_name+"] to your /etc/hosts file"
|
||||
fstore.backup_file("/etc/hosts")
|
||||
hosts_fd = open('/etc/hosts', 'r+')
|
||||
hosts_fd.seek(0, 2)
|
||||
hosts_fd.write(ip+'\t'+host_name+' '+host_name.split('.')[0]+'\n')
|
||||
hosts_fd.close()
|
||||
|
||||
return ip
|
||||
|
||||
def read_dns_forwarders():
|
||||
addrs = []
|
||||
while True:
|
||||
ip = user_input("Enter IP address for a DNS forwarder (empty to stop)", allow_empty=True)
|
||||
|
||||
if not ip:
|
||||
break
|
||||
if ip == "127.0.0.1" or ip == "::1":
|
||||
print "You cannot use localhost as a DNS forwarder"
|
||||
continue
|
||||
if not verify_ip_address(ip):
|
||||
continue
|
||||
|
||||
print "DNS forwarder %s added" % ip
|
||||
addrs.append(ip)
|
||||
|
||||
if not addrs:
|
||||
print "No DNS forwarders configured"
|
||||
|
||||
return addrs
|
||||
|
||||
def read_ds_user():
|
||||
print "The server must run as a specific user in a specific group."
|
||||
print "It is strongly recommended that this user should have no privileges"
|
||||
@ -630,7 +577,7 @@ def main():
|
||||
return 1
|
||||
|
||||
if not ip:
|
||||
ip = read_ip_address(host_name)
|
||||
ip = read_ip_address(host_name, fstore)
|
||||
ip_address = ip
|
||||
|
||||
print "The IPA Master Server will be configured with"
|
||||
|
@ -117,6 +117,59 @@ def verify_fqdn(host_name,no_host_dns=False):
|
||||
if forward != reverse:
|
||||
raise RuntimeError("The DNS forward record %s does not match the reverse address %s" % (forward, reverse))
|
||||
|
||||
def verify_ip_address(ip):
|
||||
is_ok = True
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, ip)
|
||||
except:
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET6, ip)
|
||||
except:
|
||||
print "Unable to verify IP address"
|
||||
is_ok = False
|
||||
return is_ok
|
||||
|
||||
def read_ip_address(host_name, fstore):
|
||||
while True:
|
||||
ip = ipautil.user_input("Please provide the IP address to be used for this host name", allow_empty = False)
|
||||
|
||||
if ip == "127.0.0.1" or ip == "::1":
|
||||
print "The IPA Server can't use localhost as a valid IP"
|
||||
continue
|
||||
|
||||
if verify_ip_address(ip):
|
||||
break
|
||||
|
||||
print "Adding ["+ip+" "+host_name+"] to your /etc/hosts file"
|
||||
fstore.backup_file("/etc/hosts")
|
||||
hosts_fd = open('/etc/hosts', 'r+')
|
||||
hosts_fd.seek(0, 2)
|
||||
hosts_fd.write(ip+'\t'+host_name+' '+host_name.split('.')[0]+'\n')
|
||||
hosts_fd.close()
|
||||
|
||||
return ip
|
||||
|
||||
def read_dns_forwarders():
|
||||
addrs = []
|
||||
while True:
|
||||
ip = ipautil.user_input("Enter IP address for a DNS forwarder (empty to stop)", allow_empty=True)
|
||||
|
||||
if not ip:
|
||||
break
|
||||
if ip == "127.0.0.1" or ip == "::1":
|
||||
print "You cannot use localhost as a DNS forwarder"
|
||||
continue
|
||||
if not verify_ip_address(ip):
|
||||
continue
|
||||
|
||||
print "DNS forwarder %s added" % ip
|
||||
addrs.append(ip)
|
||||
|
||||
if not addrs:
|
||||
print "No DNS forwarders configured"
|
||||
|
||||
return addrs
|
||||
|
||||
def port_available(port):
|
||||
"""Try to bind to a port on the wildcard host
|
||||
Return 1 if the port is available
|
||||
|
Loading…
Reference in New Issue
Block a user