コード例 #1
0
def update_names_module(initial_registration=False, enabled=None,
                        kite_name=None):
    """
    Update the PageKite domain and services of the 'names' module.

    - initial_registration: Boolean (optional): Register also if not enabled
    - enabled: Boolean (optional) whether PageKite is enabled
    - kite_name: String (optional)
    """
    domain_removed.send_robust(sender='pagekite', domain_type='pagekite')

    if enabled is None:
        try:
            enabled = get_pagekite_config()['enabled']
        except IndexError:
            enabled = False

    if enabled:
        # Get enabled services and kite name
        services = get_pagekite_services()[0]
        enabled_services = [service for service in services if
                            services[service]]
        if kite_name is None:
            try:
                kite_name = get_kite_details()['kite_name']
            except IndexError:
                pass
    else:
        enabled_services = None
        kite_name = None

    if initial_registration or (enabled and kite_name):
        domain_added.send_robust(
            sender='pagekite', domain_type='pagekite', name=kite_name,
            description=_('Pagekite'), services=enabled_services)
コード例 #2
0
ファイル: config.py プロジェクト: rajasekharponakala/Plinth
def set_domainname(domainname):
    """Sets machine domain name to domainname"""
    old_domainname = 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
ファイル: views.py プロジェクト: peacekeeper/plinth
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)
コード例 #4
0
ファイル: dynamicdns.py プロジェクト: niejn/Plinth
def _apply_changes(request, old_status, new_status):
    """Apply the changes to Dynamic DNS client."""
    logger.info('New status is - %s', new_status)
    logger.info('Old status was - %s', old_status)

    if new_status['dynamicdns_secret'] == '':
        new_status['dynamicdns_secret'] = old_status['dynamicdns_secret']

    if new_status['dynamicdns_ipurl'] == '':
        new_status['dynamicdns_ipurl'] = EMPTYSTRING

    if new_status['dynamicdns_update_url'] == '':
        new_status['dynamicdns_update_url'] = EMPTYSTRING

    if new_status['dynamicdns_server'] == '':
        new_status['dynamicdns_server'] = EMPTYSTRING

    if new_status['service_type'] == 'GnuDIP':
        new_status['dynamicdns_update_url'] = EMPTYSTRING
    else:
        new_status['dynamicdns_server'] = EMPTYSTRING

    if old_status != new_status:
        disable_ssl_check = "disabled"
        use_http_basic_auth = "disabled"

        if new_status['disable_SSL_cert_check']:
            disable_ssl_check = "enabled"

        if new_status['use_http_basic_auth']:
            use_http_basic_auth = "enabled"

        _run([
            'configure', '-s', new_status['dynamicdns_server'], '-d',
            new_status['dynamicdns_domain'], '-u',
            new_status['dynamicdns_user'], '-p', '-I',
            new_status['dynamicdns_ipurl'], '-U',
            new_status['dynamicdns_update_url'], '-c', disable_ssl_check, '-b',
            use_http_basic_auth
        ],
             input=new_status['dynamicdns_secret'].encode())

        if old_status['enabled']:
            domain_removed.send_robust(sender='dynamicdns',
                                       domain_type='dynamicdnsservice',
                                       name=old_status['dynamicdns_domain'])
            _run(['stop'])

        if new_status['enabled']:
            services = get_enabled_services(new_status['dynamicdns_domain'])
            domain_added.send_robust(sender='dynamicdns',
                                     domain_type='dynamicdnsservice',
                                     name=new_status['dynamicdns_domain'],
                                     description=_('Dynamic DNS Service'),
                                     services=services)
            _run(['start'])

        messages.success(request, _('Configuration updated'))
    else:
        logger.info('Nothing changed')
コード例 #5
0
ファイル: dynamicdns.py プロジェクト: SunilMohanAdapa/Plinth
def _apply_changes(request, old_status, new_status):
    """Apply the changes to Dynamic DNS client."""
    logger.info('New status is - %s', new_status)
    logger.info('Old status was - %s', old_status)

    if new_status['dynamicdns_secret'] == '':
        new_status['dynamicdns_secret'] = old_status['dynamicdns_secret']

    if new_status['dynamicdns_ipurl'] == '':
        new_status['dynamicdns_ipurl'] = EMPTYSTRING

    if new_status['dynamicdns_update_url'] == '':
        new_status['dynamicdns_update_url'] = EMPTYSTRING

    if new_status['dynamicdns_server'] == '':
        new_status['dynamicdns_server'] = EMPTYSTRING

    if new_status['service_type'] == 'GnuDIP':
        new_status['dynamicdns_update_url'] = EMPTYSTRING
    else:
        new_status['dynamicdns_server'] = EMPTYSTRING

    if old_status != new_status:
        disable_ssl_check = "disabled"
        use_http_basic_auth = "disabled"

        if new_status['disable_SSL_cert_check']:
            disable_ssl_check = "enabled"

        if new_status['use_http_basic_auth']:
            use_http_basic_auth = "enabled"

        _run(['configure', '-s', new_status['dynamicdns_server'],
              '-d', new_status['dynamicdns_domain'],
              '-u', new_status['dynamicdns_user'],
              '-p',
              '-I', new_status['dynamicdns_ipurl'],
              '-U', new_status['dynamicdns_update_url'],
              '-c', disable_ssl_check,
              '-b', use_http_basic_auth],
             input=new_status['dynamicdns_secret'].encode())

        if old_status['enabled']:
            domain_removed.send_robust(
                sender='dynamicdns', domain_type='dynamicdnsservice',
                name=old_status['dynamicdns_domain'])
            _run(['stop'])

        if new_status['enabled']:
            services = get_enabled_services(new_status['dynamicdns_domain'])
            domain_added.send_robust(
                sender='dynamicdns', domain_type='dynamicdnsservice',
                name=new_status['dynamicdns_domain'],
                description=_('Dynamic DNS Service'),
                services=services)
            _run(['start'])

        messages.success(request, _('Configuration updated'))
    else:
        logger.info('Nothing changed')
コード例 #6
0
ファイル: utils.py プロジェクト: SunilMohanAdapa/Plinth
def update_names_module(initial_registration=False, enabled=None,
                        kite_name=None):
    """
    Update the PageKite domain and services of the 'names' module.

    - initial_registration: Boolean (optional): Register also if not enabled
    - enabled: Boolean (optional) whether PageKite is enabled
    - kite_name: String (optional)
    """
    domain_removed.send_robust(sender='pagekite', domain_type='pagekite')

    if enabled is None:
        try:
            enabled = get_pagekite_config()['enabled']
        except IndexError:
            enabled = False

    if enabled:
        # Get enabled services and kite name
        services = get_pagekite_services()[0]
        enabled_services = [service for service in services if
                            services[service]]
        if kite_name is None:
            try:
                kite_name = get_kite_details()['kite_name']
            except IndexError:
                pass
    else:
        enabled_services = None
        kite_name = None

    if initial_registration or (enabled and kite_name):
        domain_added.send_robust(
            sender='pagekite', domain_type='pagekite', name=kite_name,
            description=_('Pagekite'), services=enabled_services)
コード例 #7
0
def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs):
    """Update .local domain after hostname change."""
    del sender  # Unused
    del kwargs  # Unused

    domain_removed.send_robust(sender='avahi', domain_type='domain-type-local',
                               name=old_hostname + '.local')
    domain_added.send_robust(sender='avahi', domain_type='domain-type-local',
                             name=new_hostname + '.local', services='__all__')
コード例 #8
0
ファイル: tor.py プロジェクト: petterreinholdtsen/Plinth
def __apply_changes(request, old_status, new_status):
    """Apply the changes."""
    if old_status['enabled'] == new_status['enabled'] and \
       old_status['hs_enabled'] == new_status['hs_enabled'] and \
       old_status['apt_transport_tor_enabled'] == \
       new_status['apt_transport_tor_enabled']:
        messages.info(request, _('Setting unchanged'))
        return

    if old_status['enabled'] != new_status['enabled']:
        if new_status['enabled']:
            actions.superuser_run('tor', ['enable'])
            messages.success(request, _('Tor enabled'))
        else:
            actions.superuser_run('tor', ['disable'])
            messages.success(request, _('Tor disabled'))

    if old_status['hs_enabled'] != new_status['hs_enabled']:
        if new_status['hs_enabled']:
            actions.superuser_run('tor', ['enable-hs'])
            messages.success(request, _('Tor hidden service enabled'))
        else:
            actions.superuser_run('tor', ['disable-hs'])
            messages.success(request, _('Tor hidden service disabled'))

    # Update hidden service name registered with Name Services module.
    domain_removed.send_robust(
        sender='tor', domain_type='hiddenservice')

    enabled = action_utils.service_is_enabled('tor')
    is_running = action_utils.service_is_running('tor')
    (hs_enabled, hs_hostname, hs_ports) = get_hs()

    if enabled and is_running and hs_enabled and hs_hostname:
        hs_services = []
        for service in SERVICES:
            if str(service[2]) in hs_ports:
                hs_services.append(service[0])

        domain_added.send_robust(
            sender='tor', domain_type='hiddenservice',
            name=hs_hostname, description=_('Tor Hidden Service'),
            services=hs_services)

    if old_status['apt_transport_tor_enabled'] != \
       new_status['apt_transport_tor_enabled']:
        if new_status['apt_transport_tor_enabled']:
            actions.superuser_run('tor', ['enable-apt-transport-tor'])
            messages.success(request, _('Enabled package download over Tor'))
        else:
            actions.superuser_run('tor', ['disable-apt-transport-tor'])
            messages.success(request, _('Disabled package download over Tor'))
コード例 #9
0
ファイル: tor.py プロジェクト: swechaFSMI/Plinth
def __apply_changes(request, old_status, new_status):
    """Apply the changes."""
    if old_status['enabled'] == new_status['enabled'] and \
       old_status['hs_enabled'] == new_status['hs_enabled'] and \
       old_status['apt_transport_tor_enabled'] == \
       new_status['apt_transport_tor_enabled']:
        messages.info(request, _('Setting unchanged'))
        return

    if old_status['enabled'] != new_status['enabled']:
        if new_status['enabled']:
            actions.superuser_run('tor', ['enable'])
            messages.success(request, _('Tor enabled'))
        else:
            actions.superuser_run('tor', ['disable'])
            messages.success(request, _('Tor disabled'))

    if old_status['hs_enabled'] != new_status['hs_enabled']:
        if new_status['hs_enabled']:
            actions.superuser_run('tor', ['enable-hs'])
            messages.success(request, _('Tor hidden service enabled'))
        else:
            actions.superuser_run('tor', ['disable-hs'])
            messages.success(request, _('Tor hidden service disabled'))

    # Update hidden service name registered with Name Services module.
    domain_removed.send_robust(
        sender='tor', domain_type='hiddenservice')

    enabled = action_utils.service_is_enabled('tor')
    is_running = action_utils.service_is_running('tor')
    (hs_enabled, hs_hostname, hs_ports) = get_hs()

    if enabled and is_running and hs_enabled and hs_hostname:
        hs_services = []
        for service in SERVICES:
            if str(service[2]) in hs_ports:
                hs_services.append(service[0])

        domain_added.send_robust(
            sender='tor', domain_type='hiddenservice',
            name=hs_hostname, description=_('Tor Hidden Service'),
            services=hs_services)

    if old_status['apt_transport_tor_enabled'] != \
       new_status['apt_transport_tor_enabled']:
        if new_status['apt_transport_tor_enabled']:
            actions.superuser_run('tor', ['enable-apt-transport-tor'])
            messages.success(request, _('Enabled package download over Tor'))
        else:
            actions.superuser_run('tor', ['disable-apt-transport-tor'])
            messages.success(request, _('Disabled package download over Tor'))
コード例 #10
0
ファイル: __init__.py プロジェクト: SunilMohanAdapa/Plinth
def update_hidden_service_domain(status=None):
    """Update HS domain with Name Services module."""
    if not status:
        status = utils.get_status()

    domain_removed.send_robust(
        sender='tor', domain_type='hiddenservice')

    if status['enabled'] and status['is_running'] and \
       status['hs_enabled'] and status['hs_hostname']:
        domain_added.send_robust(
            sender='tor', domain_type='hiddenservice',
            name=status['hs_hostname'], description=_('Tor Hidden Service'),
            services=status['hs_services'])
コード例 #11
0
ファイル: __init__.py プロジェクト: alexdeathway/FreedomBox
def update_hidden_service_domain(status=None):
    """Update HS domain with Name Services module."""
    if not status:
        status = utils.get_status()

    domain_removed.send_robust(sender='tor', domain_type='domain-type-tor')

    if status['enabled'] and status['is_running'] and \
       status['hs_enabled'] and status['hs_hostname']:
        services = [int(port['virtport']) for port in status['hs_ports']]
        domain_added.send_robust(sender='tor',
                                 domain_type='domain-type-tor',
                                 name=status['hs_hostname'],
                                 services=services)
コード例 #12
0
ファイル: __init__.py プロジェクト: mridulnagpal/Plinth
def update_hidden_service_domain(status=None):
    """Update HS domain with Name Services module."""
    if not status:
        status = utils.get_status()

    domain_removed.send_robust(
        sender='tor', domain_type='hiddenservice')

    if status['enabled'] and status['is_running'] and \
       status['hs_enabled'] and status['hs_hostname']:
        domain_added.send_robust(
            sender='tor', domain_type='hiddenservice',
            name=status['hs_hostname'], description=_('Tor Hidden Service'),
            services=status['hs_services'])
コード例 #13
0
ファイル: __init__.py プロジェクト: jvalleroy/plinth-debian
def update_hidden_service_domain(status=None):
    """Update HS domain with Name Services module."""
    if not status:
        status = get_status()

    domain_removed.send_robust(sender="tor", domain_type="hiddenservice")

    if status["enabled"] and status["is_running"] and status["hs_enabled"] and status["hs_hostname"]:
        domain_added.send_robust(
            sender="tor",
            domain_type="hiddenservice",
            name=status["hs_hostname"],
            description=_("Tor Hidden Service"),
            services=status["hs_services"],
        )
コード例 #14
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__')
コード例 #15
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__')
コード例 #16
0
ファイル: utils.py プロジェクト: alexdeathway/FreedomBox
def update_names_module(is_enabled=None):
    """Update the PageKite domain and services of the 'names' module."""
    domain_removed.send_robust(sender='pagekite',
                               domain_type='domain-type-pagekite')

    if is_enabled is False:
        return

    from plinth.modules.pagekite import app
    if is_enabled is None and not app.is_enabled():
        return

    config = get_config()
    enabled_services = [
        service for service, value in config['predefined_services'].items()
        if value
    ]
    if config['kite_name'] and config['kite_name'] != UNCONFIGURED_KITE:
        domain_added.send_robust(sender='pagekite',
                                 domain_type='domain-type-pagekite',
                                 name=config['kite_name'],
                                 services=enabled_services)
コード例 #17
0
ファイル: views.py プロジェクト: joelvalleroy/Plinth
def _collect_config_result(request):
    """Handle config process completion."""
    global config_process
    if not config_process:
        return

    return_code = config_process.poll()

    # Config process is not complete yet
    if return_code == None:
        return

    status = tor.get_status()

    tor.socks_service.notify_enabled(None, status['enabled'])
    tor.bridge_service.notify_enabled(None, status['enabled'])

    # Update hidden service name registered with Name Services module.
    domain_removed.send_robust(
        sender='tor', domain_type='hiddenservice')

    if status['enabled'] and status['is_running'] and \
       status['hs_enabled'] and status['hs_hostname']:
        hs_services = []
        for service in SERVICES:
            if str(service[2]) in status['hs_ports']:
                hs_services.append(service[0])

        domain_added.send_robust(
            sender='tor', domain_type='hiddenservice',
            name=status['hs_hostname'], description=_('Tor Hidden Service'),
            services=hs_services)

    if not return_code:
        messages.success(request, _('Configuration updated.'))
    else:
        messages.error(request, _('An error occurred during configuration.'))

    config_process = None
コード例 #18
0
ファイル: views.py プロジェクト: alexdeathway/FreedomBox
def _apply_changes(request, old_status, new_status):
    """Apply the changes to Dynamic DNS client."""
    logger.info('New status is - %s', new_status)
    logger.info('Old status was - %s', old_status)

    if new_status['dynamicdns_secret'] == '':
        new_status['dynamicdns_secret'] = old_status['dynamicdns_secret']

    if new_status['dynamicdns_ipurl'] == '':
        new_status['dynamicdns_ipurl'] = EMPTYSTRING

    if new_status['dynamicdns_update_url'] == '':
        new_status['dynamicdns_update_url'] = EMPTYSTRING

    if new_status['dynamicdns_server'] == '':
        new_status['dynamicdns_server'] = EMPTYSTRING

    if new_status['service_type'] == 'GnuDIP':
        new_status['dynamicdns_update_url'] = EMPTYSTRING
    else:
        new_status['dynamicdns_server'] = EMPTYSTRING

    if old_status != new_status:
        disable_ssl_check = "disabled"
        use_http_basic_auth = "disabled"
        use_ipv6 = "disabled"

        if new_status['disable_SSL_cert_check']:
            disable_ssl_check = "enabled"

        if new_status['use_http_basic_auth']:
            use_http_basic_auth = "enabled"

        if new_status.get('use_ipv6'):
            use_ipv6 = "enabled"

        # Domain name is not case sensitive, but Let's Encrypt
        # certificate paths use lower-case domain name.
        new_domain_name = new_status['dynamicdns_domain'].lower()

        _run([
            'configure',
            '-s',
            new_status['dynamicdns_server'],
            '-d',
            new_domain_name,
            '-u',
            new_status['dynamicdns_user'],
            '-p',
            '-I',
            new_status['dynamicdns_ipurl'],
            '-U',
            new_status['dynamicdns_update_url'],
            '-c',
            disable_ssl_check,
            '-b',
            use_http_basic_auth,
            '-6',
            use_ipv6,
        ],
             input=new_status['dynamicdns_secret'].encode())

        if old_status['enabled']:
            domain_removed.send_robust(sender='dynamicdns',
                                       domain_type='domain-type-dynamic',
                                       name=old_status['dynamicdns_domain'])
            _run(['stop'])

        if new_status['enabled']:
            domain_added.send_robust(sender='dynamicdns',
                                     domain_type='domain-type-dynamic',
                                     name=new_domain_name,
                                     services='__all__')
            _run(['start'])

        messages.success(request, _('Configuration updated'))
    else:
        logger.info('Nothing changed')