예제 #1
0
 def initialize(self):
     """ Parse Configuration File """
     import ConfigParser
     # Assume filepath is good, since it is already checked
     info(self.v, 'Importing Configuration File: %s' % self.filepath)
     config = ConfigParser.SafeConfigParser(allow_no_value=True)
     try:
         config.readfp(open(self.filepath, 'r'))
     except Exception, e:
         exit(1, "Error reading config file (%s): %s" % (self.filepath, e))
예제 #2
0
 def save(self):
     info(self.v, 'Saving Config File (%s)' % self.filepath)
     try:
         with open(self.filepath, 'w') as f:
             f.write("[authentication]\napi_key=%s\n\n" % self.api_key)
             f.write("[cache]\nip=%s\n\n" % self.ip)
             f.write("[records]\n")
             for key in self.records.keys():
                 f.write("%s=%s\n" % (key, self.records[key]))
     except Exception, e:
         error("Could Not Save Config File (%s) - %s" % (self.filepath, e))
예제 #3
0
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
예제 #4
0
def get_records(api_key, verbosity=0):
    v = verbosity
    url = "https://freedns.afraid.org/api/?action=getdyndns&sha=%s&style=xml"
    url = url % api_key
    info(v, "Retreiving records from %s" % url)

    # Open URL
    try:
        html_result = urlopen(url)
    except Exception, e:
        error("url(%s) - %s" % (url, e))
        return None
예제 #5
0
def update_record(record, ip, verbosity=0):
    v = verbosity
    url = "https://freedns.afraid.org/dynamic/update.php?%s&address=%s"
    url = url % (record.updateKey(), ip)
    info(v, "Updating Record %s" % url)

    # Open URL
    try:
        html_result = urlopen(url)
    except Exception, e:
        error("url(%s) - %s" % (url, e))
        return