Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- class ConfigCreator(object):
- def __init__(self, filename="conf.cfg", protocol=None, url=None, domain=None,
- username=None, password=None):
- self.collect_data(filename, protocol, url, domain, username, password)
- self.write_config()
- self.confirm_config(filename, protocol, url, domain, username, password)
- def collect_data(self, filename, protocol, url, domain, username, password):
- self.filename = filename
- if not protocol:
- protocol_correct = False
- while not protocol_correct:
- protocol = raw_input("Enter Protocol (LDAP or LDAPS): ").lower()
- confirm = raw_input("Is " + protocol + " correct? Y/N: ").lower()
- protocol_correct = True if (confirm == 'y') else False
- self.protocol = protocol
- if not url:
- url_correct = False
- while not url_correct:
- url = raw_input("Please enter server URL or IP Address: ").lower()
- confirm = raw_input("Is " + url + " correct? Y/N: ").lower()
- url_correct = True if (confirm == 'y') else False
- self.url = url
- if not domain:
- domain_correct = False
- while not domain_correct:
- domain = raw_input("Please enter the domain name: ").lower()
- confirm = raw_input("Is " + domain + " correct? Y/N: ").lower()
- domain_correct = True if (confirm == 'y') else False
- self.domain = domain
- if not username:
- username_correct = False
- while not username_correct:
- username = raw_input("Please enter your username: ").lower()
- confirm = raw_input("Is " + username + " correct? Y/N: ").lower()
- username_correct = True if (confirm == 'y') else False
- self.username = username
- if not password:
- password_correct = False
- while not password_correct:
- password = raw_input("Please enter your password: ").lower()
- confirm = raw_input("Is " + password + " correct? Y/N: ").lower()
- password_correct = True if (confirm == 'y') else False
- self.password = password
- def write_config(self):
- with open("conf.cfg", "w") as configfile:
- configfile.write("#CONF.CFG#\n")
- configfile.write(self.protocol + "\n")
- configfile.write(self.url + "\n")
- configfile.write(self.domain + "\n")
- configfile.write(self.username + "\n")
- configfile.write(self.password + "\n")
- def confirm_config(self, filename, protocol, url, domain, username, password):
- with open("conf.cfg", "r") as configfile:
- config = [line.strip() for line in configfile.readlines()]
- protocol = config[1]
- serverurl = config[2]
- domainname = config[3]
- username = config[4]
- password = config[5]
- print("Your configuration:")
- print()
- print("PROTOCOL: " + protocol)
- print("SERVER URL / IP: " + serverurl)
- print("DOMAIN: " + domainname)
- print("USERNAME: " + username)
- print("PASSWORD: " + password)
- print()
- confirm = raw_input("Is this correct? Y/N: ").lower()
- if confirm == "y":
- print("Your configuration file is complete (conf.cfg)")
- raise SystemExit
- else:
- self.__init__(filename, protocol, url, domain, username, password)
- if __name__ == "__main__":
- print "Python LDAP or LDAPS Authentication Configuration Utility."
- print
- conf = ConfigCreator()
Add Comment
Please, Sign In to add comment