Ejemplo n.º 1
0
def _renew(config, ignore_errors):
    config = freenom_dns_updater.Config(config_src(config))

    ok_count = 0

    def action(freenom: Freenom, domain: Domain):
        if freenom.need_renew(domain):
            if not freenom.renew(domain):
                raise Exception(f"unable to renew {domain.name}")

    try:
        ok_count, err_count = domain_action(action, config, ignore_errors)

        if not err_count:
            click.echo(
                f'Successfully Updated {ok_count} domain{"s" if ok_count > 1 else ""}'
            )
        else:
            click.echo(
                f'Updated {ok_count} domain{"s" if ok_count > 1 else ""}')
    except UpdateError as update_error:
        if any(msg != 'There were no changes' for msg in update_error.msgs):
            click.echo(f"Update errors: {update_error.msgs}", err=True)
    except Exception as e:
        click.echo(f"Error while updating: {e}", err=True)

    if not ok_count:
        click.secho('No record updated', fg='yellow', bold=True)
Ejemplo n.º 2
0
def record_update(user, password, domain, name, type, target, ttl):
    d = {'login': user, 'password': password, 'record': []}
    record = {'domain': domain}
    if name:
        record['name'] = name
    if type:
        record['type'] = type
    if target:
        record['target'] = target
    if ttl:
        record['ttl'] = ttl
    d['record'].append(record)
    config = freenom_dns_updater.Config(d)

    ok_count = 0
    try:
        ok_count, err_count = record_action(
            lambda freenom, rec: freenom.add_record(rec, True), config, False)

        if ok_count:
            click.echo('Record successfully added/updated')
    except UpdateError as update_error:
        if any(msg != 'There were no changes' for msg in update_error.msgs):
            click.echo(f"Update errors: {update_error.msgs}", err=True)
    except Exception as e:
        click.echo(f"Error while updating: {e}", err=True)

    if not ok_count:
        click.secho('No record updated', fg='yellow', bold=True)
Ejemplo n.º 3
0
def record_add(user, password, domain, name, type, target, ttl, update,
               priority):
    d = {'login': user, 'password': password, 'record': []}
    record = {'domain': domain}
    if name:
        record['name'] = name
    if type:
        record['type'] = type
    if target:
        record['target'] = target
    if ttl:
        record['ttl'] = ttl
    if priority:
        record['priority'] = priority

    d['record'].append(record)
    config = freenom_dns_updater.Config(d)

    ok_count, err_count = record_action(
        lambda freenom, rec: freenom.add_record(rec, update), config, False)

    if ok_count:
        click.echo('Record successfully added{}.'.format(
            "/updated" if update else ""))
    else:
        click.secho('No record updated', fg='yellow', bold=True)
Ejemplo n.º 4
0
def _update(config, ignore_errors):
    config = freenom_dns_updater.Config(config_src(config))

    ok_count, err_count = record_action(lambda freenom, rec: freenom.add_record(rec, True), config, ignore_errors)

    if ok_count:
        if not err_count:
            click.echo('Successfully Updated {} record{}'.format(ok_count, "s" if ok_count > 1 else ""))
        else:
            click.echo('Updated {} record{}'.format(ok_count, "s" if ok_count > 1 else ""))
    else:
        click.secho('No record updated', fg='yellow', bold=True)
Ejemplo n.º 5
0
def record_rm(user, password, domain, name, type, target, ttl, update):
    d = {'login': user, 'password': password, 'record': []}
    record = {'domain': domain}
    if name:
        record['name'] = name
    if type:
        record['type'] = type
    if target:
        record['target'] = target
    if ttl:
        record['ttl'] = ttl
    d['record'].append(record)
    config = freenom_dns_updater.Config(d)

    ok_count, err_count = record_action(lambda freenom, rec: freenom.remove_record(rec), config, False)

    if ok_count:
        click.echo('Record successfully removed.')
    else:
        click.secho('No record removed', fg='yellow', bold=True)
Ejemplo n.º 6
0
def _update(config, ignore_errors):
    config = freenom_dns_updater.Config(config_src(config))

    ok_count = 0
    try:
        ok_count, err_count = record_action(
            lambda freenom, rec: freenom.add_record(rec, True), config,
            ignore_errors)

        if not err_count:
            click.echo(
                f'Successfully Updated {ok_count} record{"s" if ok_count > 1 else ""}'
            )
        else:
            click.echo(
                f'Updated {ok_count} record{"s" if ok_count > 1 else ""}')
    except UpdateError as update_error:
        if any(msg != 'There were no changes' for msg in update_error.msgs):
            click.echo(f"Update errors: {update_error.msgs}", err=True)
    except Exception as e:
        click.echo(f"Error while updating: {e}", err=True)

    if not ok_count:
        click.secho('No record updated', fg='yellow', bold=True)