Exemple #1
0
def update_dns_record(secret=None, fqdn=None, zone_name=None, record_name=None,
                      ip_1=None, ip_2=None, ipv4=None, ipv6=None, ttl=None,
                      config=None):
    """
    Update a DNS record.

    :param str secret: A password like secret string. The secret string has to
      be at least 8 characters long and only alphnumeric characters are
      allowed.
    :param str fqdn: The Fully-Qualified Domain Name
      (e. g. ``www.example.com``). If you specify the argument ``fqdn``, you
      don’t have to specify the arguments ``zone_name`` and ``record_name``.
    :param str zone_name: The zone name (e. g. ``example.com``). You have to
      specify the argument ``record_name``.
    :param str record_name: The record name (e. g. ``www``). You have to
      specify the argument ``zone_name``.
    :param str ip_1: A IP address, can be version 4 or version 6.
    :param str ip_2: A second IP address, can be version 4 or version 6. Must
      be a different version than ``ip_1``.
    :param str ipv4: A IP address version 4.
    :param str ipv6: A IP address version 6.
    :param int ttl: Time to live.
    :param dict config: The configuration in the Python dictionary format
      (as returned by the function ``validate_config()``).
    """

    if not config:
        config = get_config()

    zones = config['zones']

    authenticate(secret, config)

    names = parameter_err(Names, NamesError, zones, fqdn=fqdn,
                          zone_name=zone_name, record_name=record_name)
    ipaddresses = parameter_err(IpAddresses, IpAddressesError, ip_1=ip_1,
                                ip_2=ip_2, ipv4=ipv4, ipv6=ipv6,
                                request=flask.request)

    update = jf_dns.DnsUpdate(
        nameserver=config['nameserver'],
        names=names,
        ipaddresses=ipaddresses,
        ttl=ttl,
    )
    results = update.update()

    messages = []
    for result in results:
        message = 'fqdn: {} old_ip: {} new_ip: {}'.format(
            names.fqdn,
            result['old_ip'],
            result['new_ip'],
        )
        messages.append(msg(message, result['status']))

    return ''.join(messages)
Exemple #2
0
def template_usage(remove_heading=False):
    config = False
    try:
        config = get_config()
    except Exception:
        pass

    usage = RestructuredText.read('usage.rst')

    if config and 'dyndns_domain' in config:
        usage = re.sub(r'``(<your-domain>.*)``', r'`\1 <\1>`_', usage)
        usage = usage.replace('<your-domain>',
                              'http://{}'.format(config['dyndns_domain']))
    return RestructuredText.to_html(usage, remove_heading)
Exemple #3
0
def delete_dns_record(secret=None, fqdn=None, config=None):
    if not config:
        config = get_config()
    zones = config['zones']

    authenticate(secret, config)

    names = raise_parameter_error(Names, NamesError, zones, fqdn=fqdn)

    delete = DnsUpdate(
        nameserver=config['nameserver'],
        names=names,
    )

    if delete.delete():
        return msg('Deleted "{}".'.format(names.fqdn), 'UPDATED')
    return msg('Deletion not successful "{}".'.format(names.fqdn), 'UNCHANGED')
Exemple #4
0
def home():
    config = False
    try:
        config = get_config()
    except Exception:
        pass

    if not config:
        configuration = RestructuredText.read_to_html('configuration.rst')
    else:
        configuration = ''

    content = flask.render_template(
        'home.html',
        usage=template_usage(),
        configuration=configuration,
        about=RestructuredText.read_to_html('about.rst'),
    )
    return template_base('dyndns', content)