mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
Wrap up the raw_input() to user_input() for convenience and uniformity.
This commit is contained in:
parent
72a3114a01
commit
f7ca405716
@ -81,29 +81,16 @@ def main():
|
||||
if options.usage:
|
||||
usage()
|
||||
|
||||
cont = False
|
||||
|
||||
if (len(args) != 2):
|
||||
while (cont != True):
|
||||
cn = raw_input("Group name: ")
|
||||
if (ipavalidate.String(cn, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
cn = ipautil.user_input("Group name", allow_empty = False)
|
||||
else:
|
||||
cn = args[1]
|
||||
if (ipavalidate.String(cn, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
return 1
|
||||
|
||||
cont = False
|
||||
if not options.desc:
|
||||
while (cont != True):
|
||||
desc = raw_input("Description: ")
|
||||
if (ipavalidate.String(desc, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
desc = ipautil.user_input("Description", allow_empty = False)
|
||||
else:
|
||||
desc = options.desc
|
||||
if (ipavalidate.String(desc, notEmpty=True)):
|
||||
|
@ -102,7 +102,6 @@ def main():
|
||||
groups = ""
|
||||
|
||||
match = False
|
||||
cont = False
|
||||
|
||||
all_interactive = False
|
||||
|
||||
@ -116,40 +115,23 @@ def main():
|
||||
all_interactive = True
|
||||
|
||||
if not options.gn:
|
||||
while (cont != True):
|
||||
givenname = raw_input("First name: ")
|
||||
if (ipavalidate.String(givenname, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
givenname = ipautil.user_input("First name", allow_empty = False)
|
||||
else:
|
||||
givenname = options.gn
|
||||
if (ipavalidate.String(givenname, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
return 1
|
||||
|
||||
cont = False
|
||||
if not options.sn:
|
||||
while (cont != True):
|
||||
lastname = raw_input("Last name: ")
|
||||
if (ipavalidate.String(lastname, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
lastname = ipautil.user_input("Last name", allow_empty = False)
|
||||
else:
|
||||
lastname = options.sn
|
||||
if (ipavalidate.String(lastname, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
return 1
|
||||
|
||||
cont = False
|
||||
if (len(args) != 2):
|
||||
while (cont != True):
|
||||
username = raw_input("Login name: ")
|
||||
if (ipavalidate.Plain(username, notEmpty=True, allowSpaces=False)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
username = ipautil.user_input_plain("Login name", allow_empty = False, allow_spaces = False)
|
||||
else:
|
||||
username = args[1]
|
||||
if (ipavalidate.Plain(username, notEmpty=True, allowSpaces=False)):
|
||||
@ -180,32 +162,12 @@ def main():
|
||||
# Ask the questions we don't normally force. We don't require answers
|
||||
# for these.
|
||||
if all_interactive is True:
|
||||
cont = False
|
||||
if not options.gecos:
|
||||
while (cont != True):
|
||||
gecos = raw_input("gecos []: ")
|
||||
if (ipavalidate.String(gecos, notEmpty=False)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
cont = False
|
||||
gecos = ipautil.user_input("gecos")
|
||||
if not options.directory:
|
||||
while (cont != True):
|
||||
directory = raw_input("home directory [/home/"+username+"]: ")
|
||||
if directory == "":
|
||||
directory = "/home/"+username
|
||||
if (ipavalidate.Path(directory, notEmpty=False)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
cont = False
|
||||
directory = ipautil.user_input_path("Home directory", "/home/" + username, allow_empty = True)
|
||||
if not options.shell:
|
||||
while (cont != True):
|
||||
shell = raw_input("shell [/bin/sh]: ")
|
||||
|
||||
if len(shell) < 1:
|
||||
shell = None
|
||||
cont = True
|
||||
shell = ipautil.user_input("Shell", "/bin/sh", allow_empty = False)
|
||||
|
||||
else:
|
||||
gecos = options.gecos
|
||||
|
@ -97,7 +97,6 @@ def main():
|
||||
shell = ""
|
||||
|
||||
match = False
|
||||
cont = False
|
||||
|
||||
options, args = parse_options()
|
||||
|
||||
@ -141,46 +140,23 @@ def main():
|
||||
shell = options.shell
|
||||
else:
|
||||
if not options.gn:
|
||||
while (cont != True):
|
||||
givenname = raw_input("First name: [%s] " % user.getValue('givenname'))
|
||||
if (ipavalidate.String(givenname, notEmpty=False)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
if len(givenname) < 1:
|
||||
givenname = None
|
||||
cont = True
|
||||
givenname = ipautil.user_input("First name", user.getValue('givenname'), allow_empty = False)
|
||||
else:
|
||||
givenname = options.gn
|
||||
if (ipavalidate.String(givenname, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
return 1
|
||||
|
||||
cont = False
|
||||
if not options.sn:
|
||||
while (cont != True):
|
||||
lastname = raw_input(" Last name: [%s] " % user.getValue('sn'))
|
||||
if (ipavalidate.String(lastname, notEmpty=False)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
if len(lastname) < 1:
|
||||
lastname = None
|
||||
cont = True
|
||||
lastname = ipautil.user_input("Last name", user.getValue('sn'), allow_empty = False)
|
||||
else:
|
||||
lastname = options.sn
|
||||
if (ipavalidate.String(lastname, notEmpty=True)):
|
||||
print "Please enter a value"
|
||||
return 1
|
||||
|
||||
cont = False
|
||||
if not options.mail:
|
||||
while (cont != True):
|
||||
mail = raw_input("E-mail addr: [%s]" % user.getValue('mail'))
|
||||
if (ipavalidate.Email(mail, notEmpty=False)):
|
||||
print "E-mail must include a user and domain name"
|
||||
else:
|
||||
cont = True
|
||||
mail = ipautil.user_input_email("E-mail address", user.getValue('mail'), allow_empty = True)
|
||||
else:
|
||||
mail = options.mail
|
||||
if (ipavalidate.Email(mail)):
|
||||
@ -189,32 +165,13 @@ def main():
|
||||
|
||||
# Ask the questions we don't normally force. We don't require answers
|
||||
# for these.
|
||||
cont = False
|
||||
if not options.gecos:
|
||||
while (cont != True):
|
||||
gecos = raw_input("gecos: [%s] " % user.getValue('gecos'))
|
||||
if (ipavalidate.String(gecos, notEmpty=False)):
|
||||
print "Please enter a value"
|
||||
else:
|
||||
cont = True
|
||||
gecos = ipautil.user_input("gecos", user.getValue('gecos'))
|
||||
|
||||
cont = False
|
||||
if not options.directory:
|
||||
while (cont != True):
|
||||
directory = raw_input("home directory: [%s] " % user.getValue('homeDirectory'))
|
||||
if (ipavalidate.Path(gecos, notEmpty=False)):
|
||||
print "Valid path is required"
|
||||
else:
|
||||
cont = True
|
||||
cont = False
|
||||
directory = ipautil.user_input_path("Home directory", user.getValue('homeDirectory'))
|
||||
if not options.shell:
|
||||
while (cont != True):
|
||||
shell = raw_input("shell: [%s] " % user.getValue('loginshell'))
|
||||
|
||||
if len(shell) < 1:
|
||||
shell = None
|
||||
cont = True
|
||||
cont = False
|
||||
shell = ipautil.user_input("Shell", user.getValue('loginshell'), allow_empty = False)
|
||||
|
||||
if givenname:
|
||||
user.setValue('givenname', givenname)
|
||||
|
@ -30,7 +30,7 @@ try:
|
||||
import ipaclient.ipadiscovery
|
||||
import ipaclient.ipachangeconf
|
||||
import ipaclient.ntpconf
|
||||
from ipa.ipautil import run
|
||||
from ipa.ipautil import run, user_input
|
||||
from ipa import sysrestore
|
||||
from ipa import version
|
||||
except ImportError:
|
||||
@ -70,13 +70,6 @@ def parse_options():
|
||||
|
||||
return options
|
||||
|
||||
def ask_for_confirmation(message):
|
||||
yesno = raw_input(message + " [y/N]: ")
|
||||
if not yesno or yesno.lower()[0] != "y":
|
||||
return False
|
||||
print "\n"
|
||||
return True
|
||||
|
||||
def logging_setup(options):
|
||||
# Always log everything (i.e., DEBUG) to the log
|
||||
# file.
|
||||
@ -124,7 +117,7 @@ def uninstall(options):
|
||||
print "The original nsswitch.conf configuration has been restored."
|
||||
print "You may need to restart services or reboot the machine."
|
||||
if not options.on_master:
|
||||
if ask_for_confirmation("Do you want to reboot the machine?"):
|
||||
if user_input("Do you want to reboot the machine?", False):
|
||||
try:
|
||||
run(["/usr/bin/reboot"])
|
||||
except Exception, e:
|
||||
@ -163,9 +156,7 @@ def main():
|
||||
return ret
|
||||
else:
|
||||
print "DNS discovery failed to determine your DNS domain"
|
||||
cli_domain = ""
|
||||
while cli_domain == "":
|
||||
cli_domain = raw_input("Please provide the domain name of your IPA server (ex: example.com): ")
|
||||
cli_domain = user_input("Please provide the domain name of your IPA server (ex: example.com)", allow_empty = False)
|
||||
ret = ds.search(domain=cli_domain, server=options.server)
|
||||
if not cli_domain:
|
||||
if ds.getDomainName():
|
||||
@ -180,9 +171,7 @@ def main():
|
||||
return ret
|
||||
else:
|
||||
print "DNS discovery failed to find the IPA Server"
|
||||
cli_server = ""
|
||||
while cli_server == "":
|
||||
cli_server = raw_input("Please provide your IPA server name (ex: ipa.example.com): ")
|
||||
cli_server = user_input("Please provide your IPA server name (ex: ipa.example.com)", allow_empty = False)
|
||||
ret = ds.search(domain=cli_domain, server=cli_server)
|
||||
if not cli_server:
|
||||
if ds.getServerName():
|
||||
@ -203,7 +192,7 @@ def main():
|
||||
print "If you proceed with the installation, services will be configured to always"
|
||||
print "access the discovered server for all operation and will not fail over to"
|
||||
print "other servers in case of failure.\n"
|
||||
if not ask_for_confirmation("Do you want to proceed and configure the system with fixed values with no DNS discovery?"):
|
||||
if not user_input("Do you want to proceed and configure the system with fixed values with no DNS discovery?", False):
|
||||
return ret
|
||||
|
||||
if options.realm_name and options.realm_name != ds.getRealmName():
|
||||
@ -220,7 +209,7 @@ def main():
|
||||
print "BaseDN: "+cli_basedn
|
||||
|
||||
print "\n"
|
||||
if not options.unattended and not ask_for_confirmation("Continue to configure the system with these values?"):
|
||||
if not options.unattended and not user_input("Continue to configure the system with these values?", False):
|
||||
return 1
|
||||
|
||||
# Configure ipa.conf
|
||||
|
@ -29,6 +29,7 @@ import os, sys, traceback, readline
|
||||
import stat
|
||||
import shutil
|
||||
|
||||
from ipa import ipavalidate
|
||||
from types import *
|
||||
|
||||
import re
|
||||
@ -482,6 +483,71 @@ def read_items_file(filename):
|
||||
if fd != sys.stdin: fd.close()
|
||||
return items
|
||||
|
||||
def user_input(prompt, default = None, allow_empty = True):
|
||||
if default == None:
|
||||
while True:
|
||||
ret = raw_input("%s: " % prompt)
|
||||
if allow_empty or ret.strip():
|
||||
return ret
|
||||
|
||||
if isinstance(default, basestring):
|
||||
while True:
|
||||
ret = raw_input("%s [%s]: " % (prompt, default))
|
||||
if not ret and (allow_empty or default):
|
||||
return default
|
||||
elif ret.strip():
|
||||
return ret
|
||||
if isinstance(default, bool):
|
||||
if default:
|
||||
choice = "yes"
|
||||
else:
|
||||
choice = "no"
|
||||
while True:
|
||||
ret = raw_input("%s [%s]: " % (prompt, choice))
|
||||
if not ret:
|
||||
return default
|
||||
elif ret.lower()[0] == "y":
|
||||
return True
|
||||
elif ret.lower()[0] == "n":
|
||||
return False
|
||||
if isinstance(default, int):
|
||||
while True:
|
||||
try:
|
||||
ret = raw_input("%s [%s]: " % (prompt, default))
|
||||
if not ret:
|
||||
return default
|
||||
ret = int(ret)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
return ret
|
||||
|
||||
def user_input_email(prompt, default = None, allow_empty = False):
|
||||
if default != None and allow_empty:
|
||||
prompt += " (enter \"none\" for empty)"
|
||||
while True:
|
||||
ret = user_input(prompt, default, allow_empty)
|
||||
if allow_empty and ret.lower() == "none":
|
||||
return ""
|
||||
if not ipavalidate.Email(ret, not allow_empty):
|
||||
return ret.strip()
|
||||
|
||||
def user_input_plain(prompt, default = None, allow_empty = True, allow_spaces = True):
|
||||
while True:
|
||||
ret = user_input(prompt, default, allow_empty)
|
||||
if not ipavalidate.Plain(ret, not allow_empty, allow_spaces):
|
||||
return ret
|
||||
|
||||
def user_input_path(prompt, default = None, allow_empty = True):
|
||||
if default != None and allow_empty:
|
||||
prompt += " (enter \"none\" for empty)"
|
||||
while True:
|
||||
ret = user_input(prompt, default, allow_empty)
|
||||
if allow_empty and ret.lower() == "none":
|
||||
return ""
|
||||
if not ipavalidate.Path(ret, not allow_empty):
|
||||
return ret
|
||||
|
||||
|
||||
class AttributeValueCompleter:
|
||||
'''
|
||||
|
@ -45,8 +45,7 @@ def main():
|
||||
if not ipautil.file_exists("/etc/ipa/ipa.conf"):
|
||||
print "This system does not appear to have IPA configured."
|
||||
print "Has ipa-server-install been run?"
|
||||
yesno = raw_input("Continue with radius install [y/N]? ")
|
||||
if yesno.lower() != "y":
|
||||
if not ipautil.user_input("Continue with radius install?", False)
|
||||
sys.exit(1)
|
||||
|
||||
installutils.standard_logging_setup("iparadius-install.log", False)
|
||||
|
@ -145,8 +145,7 @@ def check_dirsrv():
|
||||
if serverids:
|
||||
print ""
|
||||
print "An existing Directory Server has been detected."
|
||||
yesno = raw_input("Do you wish to remove it and create a new one? [no]: ")
|
||||
if not yesno or yesno.lower()[0] != "y":
|
||||
if not ipautil.user_input("Do you wish to remove it and create a new one?", False)
|
||||
print ""
|
||||
print "Only a single Directory Server instance is allowed on an IPA"
|
||||
print "server, the one used by IPA itself."
|
||||
@ -189,12 +188,9 @@ def main():
|
||||
if host != config.host_name:
|
||||
try:
|
||||
print "This replica was created for '%s' but this machine is named '%s'" % (host, config.host_name)
|
||||
yesno = raw_input("This may cause problems. Continue? [Y/n]: ")
|
||||
print ""
|
||||
if not yesno or yesno.lower()[0] == "y":
|
||||
pass
|
||||
else:
|
||||
if not ipautil.user_input("This may cause problems. Continue?", True)
|
||||
sys.exit(0)
|
||||
print ""
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
config.repl_password = ipautil.ipa_generate_password()
|
||||
|
@ -27,6 +27,7 @@ import traceback
|
||||
|
||||
import krbV, ldap, getpass
|
||||
|
||||
from ipa.ipautil import user_input
|
||||
from ipaserver import certs, dsinstance, httpinstance, ipaldap, installutils
|
||||
|
||||
def get_realm_name():
|
||||
@ -76,25 +77,15 @@ def choose_server_cert(server_certs):
|
||||
print "%d. %s" % (num, cert[0])
|
||||
num += 1
|
||||
|
||||
cert_num = 0
|
||||
while 1:
|
||||
cert_input = raw_input("Certificate number [1]: ")
|
||||
num = user_input("Certificate number", 1)
|
||||
print ""
|
||||
if cert_input == "":
|
||||
break
|
||||
if num < 1 or num > len(server_certs):
|
||||
print "number out of range"
|
||||
else:
|
||||
try:
|
||||
num = int(cert_input)
|
||||
except ValueError:
|
||||
print "invalid number"
|
||||
continue
|
||||
if num > len(server_certs):
|
||||
print "number out of range"
|
||||
continue
|
||||
cert_num = num - 1
|
||||
break
|
||||
return server_certs[cert_num]
|
||||
|
||||
return server_certs[num - 1]
|
||||
|
||||
def import_cert(dirname, pkcs12_fname, pkcs12_passwd, db_password):
|
||||
cdb = certs.CertDB(dirname)
|
||||
|
@ -120,7 +120,6 @@ def signal_handler(signum, frame):
|
||||
sys.exit(1)
|
||||
|
||||
def read_host_name(host_default):
|
||||
host_ok = False
|
||||
host_name = ""
|
||||
|
||||
print "Enter the fully qualified domain name of the computer"
|
||||
@ -131,19 +130,15 @@ def read_host_name(host_default):
|
||||
print ""
|
||||
if host_default == "":
|
||||
host_default = "master.example.com"
|
||||
while not host_ok:
|
||||
host_input = raw_input("Server host name [" + host_default + "]: ")
|
||||
while True:
|
||||
host_name = user_input("Server host name", host_default, allow_empty = False)
|
||||
print ""
|
||||
if host_input == "":
|
||||
host_name = host_default
|
||||
else:
|
||||
host_name = host_input
|
||||
try:
|
||||
verify_fqdn(host_name)
|
||||
except Exception, e:
|
||||
raise e
|
||||
else:
|
||||
host_ok = True
|
||||
break
|
||||
return host_name
|
||||
|
||||
def resolve_host(host_name):
|
||||
@ -178,10 +173,8 @@ def verify_ip_address(ip):
|
||||
|
||||
def read_ip_address(host_name):
|
||||
while True:
|
||||
ip = raw_input("Please provide the IP address to be used for this host name: ")
|
||||
ip = user_input("Please provide the IP address to be used for this host name", allow_empty = False)
|
||||
|
||||
if ip == "":
|
||||
continue
|
||||
if ip == "127.0.0.1" or ip == "::1":
|
||||
print "The IPA Server can't use localhost as a valid IP"
|
||||
continue
|
||||
@ -213,13 +206,12 @@ def read_ds_user():
|
||||
print "A user account named 'dirsrv' already exists. This is the user id"
|
||||
print "that the Directory Server will run as."
|
||||
print ""
|
||||
yesno = raw_input("Do you want to use the existing 'dirsrv' account? [yes]: ")
|
||||
print ""
|
||||
if not yesno or yesno.lower()[0] != "n":
|
||||
if user_input("Do you want to use the existing 'dirsrv' account?", True):
|
||||
ds_user = "dirsrv"
|
||||
else:
|
||||
ds_user = raw_input("Which account name do you want to use for the DS instance? ")
|
||||
print ""
|
||||
ds_user = user_input_plain("Which account name do you want to use for the DS instance?", allow_empty = False, allow_spaces = False)
|
||||
print ""
|
||||
except KeyError:
|
||||
ds_user = "dirsrv"
|
||||
|
||||
@ -229,37 +221,31 @@ def read_domain_name(domain_name, unattended):
|
||||
print "The domain name has been calculated based on the host name."
|
||||
print ""
|
||||
if not unattended:
|
||||
dn = raw_input("Please confirm the domain name ["+domain_name+"]: ")
|
||||
domain_name = user_input("Please confirm the domain name", domain_name)
|
||||
print ""
|
||||
if dn != "":
|
||||
domain_name = dn
|
||||
return domain_name
|
||||
|
||||
def read_realm_name(domain_name, unattended):
|
||||
print "The kerberos protocol requires a Realm name to be defined."
|
||||
print "This is typically the domain name converted to uppercase."
|
||||
print ""
|
||||
upper_dom = domain_name.upper()
|
||||
|
||||
if unattended:
|
||||
realm_name = upper_dom
|
||||
else:
|
||||
realm_name = raw_input("Please provide a realm name ["+upper_dom+"]: ")
|
||||
print ""
|
||||
if realm_name == "":
|
||||
realm_name = upper_dom
|
||||
else:
|
||||
upper_dom = realm_name.upper()
|
||||
if upper_dom != realm_name:
|
||||
print "An upper-case realm name is required."
|
||||
dom_realm = raw_input("Do you want to use "+upper_dom+" as realm name ? [yes]: ")
|
||||
return domain_name.upper()
|
||||
realm_name = user_input("Please provide a realm name", domain_name.upper())
|
||||
upper_dom = realm_name.upper()
|
||||
if upper_dom != realm_name:
|
||||
print "An upper-case realm name is required."
|
||||
if not user_input("Do you want to use " + upper_dom + " as realm name?", True):
|
||||
print ""
|
||||
if dom_realm and dom_realm.lower()[0] != "y":
|
||||
print "An upper-case realm name is required. Unable to continue."
|
||||
sys.exit(1)
|
||||
else:
|
||||
realm_name = upper_dom
|
||||
print "An upper-case realm name is required. Unable to continue."
|
||||
sys.exit(1)
|
||||
else:
|
||||
realm_name = upper_dom
|
||||
print ""
|
||||
return realm_name
|
||||
|
||||
|
||||
def read_dm_password():
|
||||
print "Certain directory server operations require an administrative user."
|
||||
print "This user is referred to as the Directory Manager and has full access"
|
||||
@ -284,10 +270,7 @@ def check_dirsrv(unattended):
|
||||
if serverids:
|
||||
print ""
|
||||
print "An existing Directory Server has been detected."
|
||||
if unattended:
|
||||
sys.exit(1)
|
||||
yesno = raw_input("Do you wish to remove it and create a new one? [no]: ")
|
||||
if not yesno or yesno.lower()[0] != "y":
|
||||
if unattended or user_input("Do you wish to remove it and create a new one?", False):
|
||||
print ""
|
||||
print "Only a single Directory Server instance is allowed on an IPA"
|
||||
print "server, the one used by IPA itself."
|
||||
@ -354,8 +337,7 @@ def main():
|
||||
if options.uninstall:
|
||||
if not options.unattended:
|
||||
print "\nThis is a NON REVERSIBLE operation and will delete all data and configuration!\n"
|
||||
yesno = raw_input("Are you sure you want to continue with the uninstall procedure?:[NO/yes] ")
|
||||
if not yesno or yesno.lower() != "yes":
|
||||
if not user_input("Are you sure you want to continue with the uninstall procedure?", False)
|
||||
print ""
|
||||
print "Aborting uninstall operation."
|
||||
sys.exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user