Exemplo n.º 1
0
def main():
    """
    Main routine
    """
    config = DDNSConfig()
    record_manager = DDNSDomainRecordManager(config)

    # get current public ip for this server
    if config.pifn_enable:
        current_public_ip = DDNSUtils.get_interface_address(
            config.pifn_interface)
    else:
        current_public_ip = DDNSUtils.get_current_public_ip()
    if not current_public_ip:
        DDNSUtils.err_and_exit("Failed to get current public IP")

    for local_record in record_manager.local_record_list:
        if local_record.subdomain == '*':
            dns_resolved_ip = DDNSUtils.get_dns_resolved_ip(
                'xxx', local_record.domainname)
        else:
            dns_resolved_ip = DDNSUtils.get_dns_resolved_ip(
                local_record.subdomain, local_record.domainname)

        if local_record.type == "AAAA":
            current_ip = DDNSUtils.get_interface_ipv6_address(
                local_record.interface)
        else:
            current_ip = current_public_ip

        if current_ip == dns_resolved_ip:
            DDNSUtils.info("Skipped as no changes for DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # If current public IP doesn't equal to current DNS resolved ip, only in three cases:
        # 1. The new synced IP for remote record in Aliyun doesn't take effect yet
        # 2. remote record's IP in Aliyun server has changed
        # 3. current public IP is changed
        remote_record = record_manager.fetch_remote_record(local_record)
        if not remote_record:
            DDNSUtils.err("Failed finding remote DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        if current_ip == remote_record.value:
            DDNSUtils.info("Skipped as we already updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # if we can fetch remote record and record's value doesn't equal to public IP
        sync_result = record_manager.update(remote_record, current_ip,
                                            local_record.type)

        if not sync_result:
            DDNSUtils.err("Failed updating DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
        else:
            DDNSUtils.info("Successfully updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
Exemplo n.º 2
0
def main():
    """
    Main routine
    """
    config = DDNSConfig()
    record_manager = DDNSDomainRecordManager(config)

    for local_record in record_manager.local_record_list:
        family = AF_INET if local_record.type == 'A' else AF_INET6
        interface = local_record.interface
        if interface is None:
            current_public_ip = {
                AF_INET: DDNSUtils.get_current_public_ip(),
                AF_INET6: DDNSUtils.get_current_public_ipv6()
            }
        else:
            current_public_ip = {
                AF_INET: DDNSUtils.get_interface_address(interface),
                AF_INET6: DDNSUtils.get_interface_address(interface, AF_INET6)
            }

        if not current_public_ip:
            DDNSUtils.info(
                "Unable to get current IP for [{rec.subdomain}.{rec.domainname}.{rec.type}]"
                .format(rec=local_record))
            continue

        dns_resolved_ip = DDNSUtils.get_dns_resolved_ip(
            local_record.subdomain, local_record.domainname, family)
        if current_public_ip[family] == dns_resolved_ip:
            DDNSUtils.info("Skipped as no changes for DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}.{rec.type}]".format(rec=local_record))
            continue

        # If current public IP doesn't equal to current DNS resolved ip, only in three cases:
        # 1. The new synced IP for remote record in Aliyun doesn't take effect yet
        # 2. remote record's IP in Aliyun server has changed
        # 3. current public IP is changed
        remote_record = record_manager.fetch_remote_record(local_record)
        if not remote_record:
            DDNSUtils.err("Failed finding remote DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        if current_public_ip[family] == remote_record.value:
            DDNSUtils.info("Skipped as we already updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # if we can fetch remote record and record's value doesn't equal to public IP
        record_type = 'A' if family == AF_INET else 'AAAA'
        sync_result = record_manager.update(remote_record,
                                            current_public_ip[family],
                                            record_type)
        if not sync_result:
            DDNSUtils.err("Failed updating DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
        else:
            DDNSUtils.info("Successfully updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
Exemplo n.º 3
0
def main(method, *args):
    """
    Main routine
    """
    config = DDNSConfig()
    record_manager = DDNSDomainRecordManager(config)

    # get current public ip for this server
    def switch(m):
        switcher = {
            "net": lambda: DDNSUtils.get_current_public_ip(),
            "static": lambda: args[0],
        }
        return switcher.get(m, lambda: "net|static 10.0.0.1")

    func = switch(method)
    current_public_ip = func()

    if not current_public_ip:
        DDNSUtils.err_and_exit("Failed to get current public IP")

    for local_record in record_manager.local_record_list:
        dns_resolved_ip = DDNSUtils.get_dns_resolved_ip(local_record.subdomain,
                                                        local_record.domainname)

        if current_public_ip == dns_resolved_ip:
            DDNSUtils.info("Skipped as no changes for DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # If current public IP doesn't equal to current DNS resolved ip, only in three cases:
        # 1. The new synced IP for remote record in Aliyun doesn't take effect yet
        # 2. remote record's IP in Aliyun server has changed
        # 3. current public IP is changed
        remote_record = record_manager.fetch_remote_record(local_record)
        if not remote_record:
            DDNSUtils.err("Failed finding remote DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        if current_public_ip == remote_record.value:
            DDNSUtils.info("Skipped as we already updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # if we can fetch remote record and record's value doesn't equal to public IP
        sync_result = record_manager.update(remote_record, current_public_ip)
        if not sync_result:
            DDNSUtils.err("Failed updating DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
        else:
            DDNSUtils.info("Successfully updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
Exemplo n.º 4
0
def main():
    """
    Main routine
    """
    config = DDNSConfig()
    record_manager = DDNSDomainRecordManager(config)

    # get current public ip for this server
    current_public_ip = DDNSUtils.get_current_public_ip()
    if not current_public_ip:
        DDNSUtils.err_and_exit("Failed to get current public IP")

    for local_record in record_manager.local_record_list:
        dns_resolved_ip = DDNSUtils.get_dns_resolved_ip(local_record.subdomain,
                                                        local_record.domainname)

        if current_public_ip == dns_resolved_ip:
            DDNSUtils.info("Skipped as no changes for DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # If current public IP doesn't equal to current DNS resolved ip, only in three cases:
        # 1. The new synced IP for remote record in Aliyun doesn't take effect yet
        # 2. remote record's IP in Aliyun server has changed
        # 3. current public IP is changed
        remote_record = record_manager.fetch_remote_record(local_record)
        if not remote_record:
            DDNSUtils.err("Failed finding remote DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        if current_public_ip == remote_record.value:
            DDNSUtils.info("Skipped as we already updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
            continue

        # if we can fetch remote record and record's value doesn't equal to public IP
        sync_result = record_manager.update(remote_record, current_public_ip)
        if not sync_result:
            DDNSUtils.err("Failed updating DomainRecord" \
                          "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))
        else:
            DDNSUtils.info("Successfully updated DomainRecord" \
                           "[{rec.subdomain}.{rec.domainname}]".format(rec=local_record))