Exemple #1
0
def obtain(request, domain):
    """Obtain and install a certificate for a given domain."""
    try:
        actions.superuser_run('letsencrypt', ['obtain', '--domain', domain])
        messages.success(
            request,
            _('Certificate successfully obtained for domain {domain}').format(
                domain=domain))
        successful_obtain = True
    except ActionError as exception:
        messages.error(
            request,
            _('Failed to obtain certificate for domain {domain}: {error}').
            format(domain=domain, error=exception.args[2]))
        successful_obtain = False

    if domain == config.get_domainname() and successful_obtain:
        try:
            actions.superuser_run('letsencrypt', ['manage_hooks', 'enable'])
            messages.success(
                request,
                _('Certificate renewal management enabled for {domain}.').
                format(domain=domain))
        except ActionError as exception:
            messages.error(
                request,
                _('Failed to enable certificate renewal management for '
                  '{domain}: {error}').format(domain=domain,
                                              error=exception.args[2]))

    return redirect(reverse_lazy('letsencrypt:index'))
Exemple #2
0
def profile(request):
    """Provide the user's profile for download."""
    username = request.user.username
    domainname = config.get_domainname()

    if not config.get_domainname():
        domainname = config.get_hostname()

    profile_string = actions.superuser_run(
        'openvpn', ['get-profile', username, domainname])

    response = HttpResponse(profile_string,
                            content_type='application/x-openvpn-profile')
    response['Content-Disposition'] = \
        'attachment; filename={username}.ovpn'.format(username=username)

    return response
Exemple #3
0
def enable_renewal_management(domain):
    if domain == config.get_domainname():
        try:
            actions.superuser_run('letsencrypt', ['manage_hooks', 'enable'])
            logger.info(
                _('Certificate renewal management enabled for {domain}.')
                .format(domain=domain))
        except ActionError as exception:
            logger.error(
                _('Failed to enable certificate renewal management for '
                  '{domain}: {error}').format(
                      domain=domain, error=exception.args[2]))
Exemple #4
0
def get_status():
    """Get the current settings."""
    status = actions.superuser_run('letsencrypt', ['get-status'])
    status = json.loads(status)
    curr_dom = config.get_domainname()
    current_domain = {
        'name': curr_dom,
        'has_cert': (curr_dom in status['domains'] and
                     status['domains'][curr_dom]['certificate_available']),
        'manage_hooks_status': get_manage_hooks_status()
    }
    status['current_domain'] = current_domain

    for domain_type, domains in names.domains.items():
        # XXX: Remove when Let's Encrypt supports .onion addresses
        if domain_type == 'hiddenservice':
            continue

        for domain in domains:
            status['domains'].setdefault(domain, {})

    return status