Пример #1
0
def set_domainname(domainname):
    """Sets machine domain name to domainname"""
    old_domainname = config.get_domainname()

    # Domain name should be ASCII. If it's unicode, convert to ASCII.
    domainname = str(domainname)

    LOGGER.info('Changing domain name to - %s', domainname)
    actions.superuser_run('domainname-change', [domainname])

    domainname_change.send_robust(sender='config',
                                  old_domainname=old_domainname,
                                  new_domainname=domainname)

    # Update domain registered with Name Services module.
    domain_removed.send_robust(sender='config', domain_type='domainname')
    if domainname:
        try:
            domainname_services = firewall.get_enabled_services(
                zone='external')
        except actions.ActionError:
            # This happens when firewalld is not installed.
            # TODO: Are these services actually enabled?
            domainname_services = [service[0] for service in SERVICES]

        domain_added.send_robust(sender='config', domain_type='domainname',
                                 name=domainname, description=_('Domain Name'),
                                 services=domainname_services)
Пример #2
0
def set_domainname(domainname):
    """Sets machine domain name to domainname"""
    old_domainname = config.get_domainname()

    # Domain name should be ASCII. If it's unicode, convert to ASCII.
    domainname = str(domainname)

    LOGGER.info('Changing domain name to - %s', domainname)
    actions.superuser_run('domainname-change', [domainname])

    domainname_change.send_robust(sender='config',
                                  old_domainname=old_domainname,
                                  new_domainname=domainname)

    # Update domain registered with Name Services module.
    domain_removed.send_robust(sender='config', domain_type='domainname')
    if domainname:
        try:
            domainname_services = firewall.get_enabled_services(
                zone='external')
        except actions.ActionError:
            # This happens when firewalld is not installed.
            # TODO: Are these services actually enabled?
            domainname_services = [service[0] for service in SERVICES]

        domain_added.send_robust(sender='config',
                                 domain_type='domainname',
                                 name=domainname,
                                 description=_('Domain Name'),
                                 services=domainname_services)
Пример #3
0
    def __init__(self):
        """The app's constructor"""
        super().__init__()
        self._add_ui_components()
        self._add_daemons()
        self._add_firewall_ports()

        # /rspamd location
        webserver = Webserver(
            'webserver-email',  # unique id
            'email-server-freedombox',  # config file name
            urls=['https://{host}/rspamd'])
        self.add(webserver)

        # Let's Encrypt event hook
        default_domain = get_domainname()
        domains = [default_domain] if default_domain else []
        letsencrypt = LetsEncrypt('letsencrypt-email-server',
                                  domains=domains,
                                  daemons=['postfix', 'dovecot'],
                                  should_copy_certificates=False,
                                  managing_app='email_server')
        self.add(letsencrypt)

        if not domains:
            logger.warning('Could not fetch the FreedomBox domain name!')
Пример #4
0
def get_status(request):
    """Return the current status"""
    return {
        'hostname': get_hostname(),
        'domainname': config.get_domainname(),
        'language': get_language(request)
    }
Пример #5
0
 def get_initial(self):
     """Return the current status"""
     return {
         'hostname': config.get_hostname(),
         'domainname': config.get_domainname(),
         'homepage': config.get_home_page(),
         'advanced_mode': config.get_advanced_mode(),
     }
Пример #6
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
Пример #7
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
Пример #8
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]))
Пример #9
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]))
Пример #10
0
def get_domains():
    """Return the list of domains that ejabberd is interested in.

    XXX: Retrieve the list from ejabberd configuration.

    """
    if app.needs_setup():
        return []

    domain_name = config.get_domainname()
    if domain_name:
        return [domain_name]

    return []
Пример #11
0
def setup(helper, old_version=None):
    """Install and configure the module."""
    domainname = config.get_domainname()
    logger.info('ejabberd service domainname - %s', domainname)

    helper.call('pre', actions.superuser_run, 'ejabberd',
                ['pre-install', '--domainname', domainname])
    # XXX: Configure all other domain names
    helper.install(managed_packages)
    helper.call('post',
                app.get_component('letsencrypt-ejabberd').setup_certificates,
                [domainname])
    helper.call('post', actions.superuser_run, 'ejabberd',
                ['setup', '--domainname', domainname])
    helper.call('post', app.enable)
Пример #12
0
def get_domains():
    """Return the list of domains that ejabberd is interested in.

    XXX: Retrieve the list from ejabberd configuration.

    """
    setup_helper = globals()['setup_helper']
    if setup_helper.get_state() == 'needs-setup':
        return []

    domain_name = config.get_domainname()
    if domain_name:
        return [domain_name]

    return []
Пример #13
0
def check_postfix_domains(title=''):
    diagnosis = models.MainCfDiagnosis(title, action='set_up')
    domain = get_domainname() or 'localhost'
    postconf_keys = (k for k in managed_keys if not k.startswith('_'))
    conf = postconf.get_many_unsafe(postconf_keys, flag='-x')

    dest_set = set(postconf.parse_maps(conf['mydestination']))
    deletion_set = set()

    temp = _amend_mailname(domain)
    if temp is not None:
        diagnosis.error('Set /etc/mailname to %s', temp)
        diagnosis.flag('_mailname', temp)

    # Amend $mydomain and conf['mydomain']
    temp = _amend_mydomain(conf['mydomain'], domain)
    if temp is not None:
        diagnosis.error('Set $mydomain to %s', temp)
        diagnosis.flag('mydomain', temp)
        deletion_set.add(conf['mydomain'])
        conf['mydomain'] = temp

    # Amend $myhostname and conf['myhostname']
    temp = _amend_myhostname(conf['myhostname'], conf['mydomain'])
    if temp is not None:
        diagnosis.error('Set $myhostname to %s', temp)
        diagnosis.flag('myhostname', temp)
        deletion_set.add(conf['myhostname'])
        conf['myhostname'] = temp

    # Delete old domain names
    deletion_set.discard('localhost')
    dest_set.difference_update(deletion_set)

    # Amend $mydestination
    temp = _amend_mydestination(dest_set, conf['mydomain'], conf['myhostname'],
                                diagnosis.error)
    if temp is not None:
        diagnosis.flag('mydestination', temp)
    elif len(deletion_set) > 0:
        corrected_value = ', '.join(sorted(dest_set))
        diagnosis.error('Update $mydestination')
        diagnosis.flag('mydestination', corrected_value)

    return diagnosis
Пример #14
0
def set_domains(primary_domain=None):
    """Set the primary domain and all the domains for postfix."""
    all_domains = DomainName.list_names()
    if not primary_domain:
        primary_domain = get_domains()['primary_domain']
        if primary_domain not in all_domains:
            primary_domain = config.get_domainname() or list(all_domains)[0]

    # Update configuration and don't restart daemons
    superuser_run(
        'email',
        ['domain', 'set_domains', primary_domain, ','.join(all_domains)])
    superuser_run('email', ['dkim', 'setup_dkim', primary_domain])

    # Copy certificates (self-signed if needed) and restart daemons
    app = App.get('email')
    app.get_component('letsencrypt-email-postfix').setup_certificates()
    app.get_component('letsencrypt-email-dovecot').setup_certificates()
Пример #15
0
def setup(helper, old_version=None):
    """Install and configure the module."""
    domainname = config.get_domainname()
    logger.info('ejabberd service domainname - %s', domainname)

    helper.call('pre', actions.superuser_run, 'ejabberd',
                ['pre-install', '--domainname', domainname])
    # XXX: Configure all other domain names
    helper.install(managed_packages)
    helper.call('post',
                app.get_component('letsencrypt-ejabberd').setup_certificates,
                [domainname])
    helper.call('post', actions.superuser_run, 'ejabberd',
                ['setup', '--domainname', domainname])
    helper.call('post', app.enable)

    # Configure STUN/TURN only if there's a valid TLS domain set for Coturn
    configuration = app.get_component('turn-ejabberd').get_configuration()
    update_turn_configuration(configuration, force=True)
Пример #16
0
def set_domainname(domainname, old_domainname):
    """Sets machine domain name to domainname"""
    old_domainname = config.get_domainname()

    # Domain name should be ASCII. If it's unicode, convert to ASCII.
    domainname = str(domainname)

    LOGGER.info('Changing domain name to - %s', domainname)
    actions.superuser_run('domainname-change', [domainname])

    # Update domain registered with Name Services module.
    if old_domainname:
        domain_removed.send_robust(sender='config',
                                   domain_type='domain-type-static',
                                   name=old_domainname)

    if domainname:
        domain_added.send_robust(sender='config',
                                 domain_type='domain-type-static',
                                 name=domainname, services='__all__')
Пример #17
0
def set_hostname(hostname):
    """Sets machine hostname to hostname"""
    old_hostname = config.get_hostname()
    domainname = config.get_domainname()

    # Hostname should be ASCII. If it's unicode but passed our
    # valid_hostname check, convert
    hostname = str(hostname)

    pre_hostname_change.send_robust(sender='config', old_hostname=old_hostname,
                                    new_hostname=hostname)

    LOGGER.info('Changing hostname to - %s', hostname)
    actions.superuser_run('hostname-change', [hostname])

    LOGGER.info('Setting domain name after hostname change - %s', domainname)
    actions.superuser_run('domainname-change', [domainname])

    post_hostname_change.send_robust(sender='config',
                                     old_hostname=old_hostname,
                                     new_hostname=hostname)
Пример #18
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
Пример #19
0
def set_hostname(hostname):
    """Sets machine hostname to hostname"""
    old_hostname = get_hostname()
    domainname = config.get_domainname()

    # Hostname should be ASCII. If it's unicode but passed our
    # valid_hostname check, convert to ASCII.
    hostname = str(hostname)

    pre_hostname_change.send_robust(sender='config',
                                    old_hostname=old_hostname,
                                    new_hostname=hostname)

    LOGGER.info('Changing hostname to - %s', hostname)
    actions.superuser_run('hostname-change', [hostname])

    post_hostname_change.send_robust(sender='config',
                                     old_hostname=old_hostname,
                                     new_hostname=hostname)

    LOGGER.info('Setting domain name after hostname change - %s', domainname)
    actions.superuser_run('domainname-change', [domainname])
Пример #20
0
def set_domainname(domainname, old_domainname):
    """Sets machine domain name to domainname"""
    old_domainname = config.get_domainname()

    # Domain name is not case sensitive, but Let's Encrypt certificate
    # paths use lower-case domain name.
    domainname = domainname.lower()

    LOGGER.info('Changing domain name to - %s', domainname)
    actions.superuser_run('domainname-change', [domainname])

    # Update domain registered with Name Services module.
    if old_domainname:
        domain_removed.send_robust(sender='config',
                                   domain_type='domain-type-static',
                                   name=old_domainname)

    if domainname:
        domain_added.send_robust(sender='config',
                                 domain_type='domain-type-static',
                                 name=domainname,
                                 services='__all__')
Пример #21
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
Пример #22
0
def get_status(request):
    """Return the current status"""
    return {'hostname': get_hostname(),
            'domainname': config.get_domainname(),
            'language': get_language(request)}
Пример #23
0
def get_domains():
    """Return the list of domains configured."""
    default_domain = get_domainname()
    return [default_domain] if default_domain else []
Пример #24
0
 def get_context_data(self, *args, **kwargs):
     """Add domain information to view context."""
     context = super().get_context_data(*args, **kwargs)
     context['domainname'] = config.get_domainname()
     return context