exit(1, "Error reading config file (%s): %s" % (self.filepath, e)) # Error Check if not config.has_section('authentication'): exit(1, "Malformed Config File. Missing 'authentication' section") if not config.has_option('authentication', 'api_key'): exit(1, "Malformed Config File. Missing 'api_key' option") # Create a dictionary of config values config_dict = {} for section in config.sections(): config_dict[section] = {} for name, value in config.items(section): config_dict[section][name] = value extra(self.v, "Section: %s\nName: %s\nValue: %s" % (section, name, value)) # Transform dict into Config Object self.api_key = config_dict['authentication']['api_key'] if config.has_option('cache', 'ip'): self.ip = config_dict['cache']['ip'] if config.has_section('records'): for key in config_dict['records'].keys(): host = key value = config_dict['records'][host] self.records[host] = value # Make sure api key is correct from re import match as re_match if not re_match('[0-9a-fA-F]{40}', self.api_key):
def get_external_ip(verbosity=0): v = verbosity url = "http://checkip.dyndns.org" info(v, "Retreiving current external ip from %s" % url) # Open URL try: html_result = urlopen(url) except Exception, e: error("Url(%s) - %s" % (url, e)) return None # Read result ip_string = html_result.read().strip() extra(v, "Full HTML Result: %s" % ip_string) # Parse out IP ip = None if ip_string is not None: regex = '^.*Current IP Address: ([0-9.]*).*$' ip = re_sub(regex, r'\1', ip_string) extra(v, "Retreived IP: %s" % ip) return ip class Record: def __init__(self, record_dict=None): self.host = ''