Esempio n. 1
0
def test_service_checks():
    """Test basic checks on status of an arbitrary service."""
    assert not service_is_running(UNKNOWN)
    assert not service_is_enabled(UNKNOWN)

    # expected is best if: generic. Alternatives: systemd-sysctl, logrotate
    expected = 'networking'
    if not service_is_running(expected):
        pytest.skip(f'Needs service {expected} running.')

    assert service_is_enabled(expected)
Esempio n. 2
0
def get_status():
    """Return the current status"""
    output = actions.superuser_run('tor', ['get-ports'])
    port_info = output.split('\n')
    ports = {}
    for line in port_info:
        try:
            (key, val) = line.split()
            ports[key] = val
        except ValueError:
            continue

    output = actions.superuser_run('tor', ['get-hs'])
    output = output.strip()
    if output == '':
        hs_enabled = False
        hs_hostname = 'Not Configured'
        hs_ports = ''
    elif output == 'error':
        hs_enabled = False
        hs_hostname = 'Not available (Run Tor at least once)'
        hs_ports = ''
    else:
        hs_enabled = True
        hs_info = output.split()
        hs_hostname = hs_info[0]
        hs_ports = hs_info[1]

    return {'enabled': action_utils.service_is_enabled('tor'),
            'is_running': action_utils.service_is_running('tor'),
            'ports': ports,
            'hs_enabled': hs_enabled,
            'hs_hostname': hs_hostname,
            'hs_ports': hs_ports,
            'apt_transport_tor_enabled': is_apt_transport_tor_enabled()}
Esempio n. 3
0
    def is_enabled(self):
        """Return if the daemon/unit is enabled."""
        if self.alias:
            # XXX: Handling alias should not be done here. service_is_enabled()
            # should return True even for an alias. Currently, in addition to
            # return code we are also checking the printed value. This makes
            # the implementation less future-proof as new values could printed
            # by the command. A fixed systemd bug
            # https://github.com/systemd/systemd/issues/18134 also currently
            # gives incorrect exit code for 'alias' case. See:
            # https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/1980
            if action_utils.service_is_enabled(self.alias,
                                               strict_check=self.strict_check):
                return True

        return action_utils.service_is_enabled(self.unit,
                                               strict_check=self.strict_check)
Esempio n. 4
0
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'))
Esempio n. 5
0
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'))
Esempio n. 6
0
def test_service_enable_and_disable():
    """Test enabling and disabling of an arbitrary service."""
    # service is best if: non-essential part of FreedomBox that restarts fast
    service = 'unattended-upgrades'
    if not service_is_enabled(service):
        reason = f'Needs service {service} enabled.'
        pytest.skip(reason)

    service_disable(service)
    assert not service_is_running(service)
    service_enable(service)
    assert service_is_running(service)

    # Ignore unknown services, don't fail:
    service_disable(UNKNOWN)
    service_enable(UNKNOWN)
Esempio n. 7
0
def get_status():
    """Return the current status"""
    output = actions.superuser_run('tor', ['get-ports'])
    port_info = output.split('\n')
    ports = {}
    for line in port_info:
        try:
            (key, val) = line.split()
            ports[key] = val
        except ValueError:
            continue

    (hs_enabled, hs_hostname, hs_ports) = get_hs()

    return {'enabled': action_utils.service_is_enabled('tor'),
            'is_running': action_utils.service_is_running('tor'),
            'ports': ports,
            'hs_enabled': hs_enabled,
            'hs_hostname': hs_hostname,
            'hs_ports': hs_ports,
            'apt_transport_tor_enabled': is_apt_transport_tor_enabled()}
Esempio n. 8
0
def get_status():
    """Return the current status"""
    output = actions.superuser_run('tor', ['get-ports'])
    port_info = output.split('\n')
    ports = {}
    for line in port_info:
        try:
            (key, val) = line.split()
            ports[key] = val
        except ValueError:
            continue

    (hs_enabled, hs_hostname, hs_ports) = get_hs()

    return {'enabled': action_utils.service_is_enabled('tor'),
            'is_running': action_utils.service_is_running('tor'),
            'ports': ports,
            'hs_enabled': hs_enabled,
            'hs_hostname': hs_hostname,
            'hs_ports': hs_ports,
            'apt_transport_tor_enabled': is_apt_transport_tor_enabled()}
Esempio n. 9
0
def get_status():
    """Return the current status"""
    output = actions.superuser_run('tor', ['get-ports'])
    port_info = output.split('\n')
    ports = {}
    for line in port_info:
        try:
            (key, val) = line.split()
            ports[key] = val
        except ValueError:
            continue

    output = actions.superuser_run('tor', ['get-hs'])
    output = output.strip()
    if output == '':
        hs_enabled = False
        hs_hostname = 'Not Configured'
        hs_ports = ''
    elif output == 'error':
        hs_enabled = False
        hs_hostname = 'Not available (Run Tor at least once)'
        hs_ports = ''
    else:
        hs_enabled = True
        hs_info = output.split()
        hs_hostname = hs_info[0]
        hs_ports = hs_info[1]

    return {
        'enabled': action_utils.service_is_enabled('tor'),
        'is_running': action_utils.service_is_running('tor'),
        'ports': ports,
        'hs_enabled': hs_enabled,
        'hs_hostname': hs_hostname,
        'hs_ports': hs_ports,
        'apt_transport_tor_enabled': is_apt_transport_tor_enabled()
    }
Esempio n. 10
0
def init():
    """Initialize the Tor module."""
    menu = cfg.main_menu.get('apps:index')
    menu.add_urlname(_('Anonymity Network (Tor)'), 'glyphicon-eye-close',
                     'tor:index', 100)

    # Register hidden service name with Name Services module.
    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])
    else:
        hs_hostname = None
        hs_services = None

    domain_added.send_robust(
        sender='tor', domain_type='hiddenservice',
        name=hs_hostname, description=_('Tor Hidden Service'),
        services=hs_services)
Esempio n. 11
0
def init():
    """Initialize the Tor module."""
    menu = cfg.main_menu.get('apps:index')
    menu.add_urlname(_('Anonymity Network (Tor)'), 'glyphicon-eye-close',
                     'tor:index', 100)

    # Register hidden service name with Name Services module.
    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])
    else:
        hs_hostname = None
        hs_services = None

    domain_added.send_robust(
        sender='tor', domain_type='hiddenservice',
        name=hs_hostname, description=_('Tor Hidden Service'),
        services=hs_services)
Esempio n. 12
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('tor@plinth', strict_check=True)
Esempio n. 13
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled(managed_services[0]) and
            action_utils.webserver_is_enabled('tahoe-plinth'))
Esempio n. 14
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled("ejabberd") and action_utils.webserver_is_enabled("jwchat-plinth")
Esempio n. 15
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('mumble-server')
Esempio n. 16
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled(managed_services[0]) and
            action_utils.webserver_is_enabled('tahoe-plinth'))
Esempio n. 17
0
def is_enabled():
    """Return whether the service is enabled."""
    return action_utils.service_is_enabled('minetest-server')
Esempio n. 18
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('tor@plinth')
Esempio n. 19
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('privoxy')
Esempio n. 20
0
def is_enabled():
    """Return whether service is enabled."""
    return action_utils.service_is_enabled(managed_services[0])
Esempio n. 21
0
def is_enabled():
    """Return whether the service is enabled."""
    return action_utils.service_is_enabled('quasselcore')
Esempio n. 22
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('node-restore')
Esempio n. 23
0
def is_enabled():
    """Return whether service is enabled."""
    return action_utils.service_is_enabled(managed_services[0])
Esempio n. 24
0
 def is_enabled(self):
     """Return whether the uWSGI configuration is enabled."""
     return action_utils.uwsgi_is_enabled(self.uwsgi_name) \
         and action_utils.service_is_enabled('uwsgi')
Esempio n. 25
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('privoxy')
Esempio n. 26
0
 def _default_is_enabled(self):
     """Returns is_enabled relying on a correct service_id"""
     return action_utils.service_is_enabled(self.service_id)
Esempio n. 27
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('avahi-daemon')
Esempio n. 28
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('openvpn@freedombox')
Esempio n. 29
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('openvpn@freedombox')
Esempio n. 30
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled('transmission-daemon') and
            action_utils.webserver_is_enabled('transmission-plinth'))
Esempio n. 31
0
 def is_enabled(self):
     """Return if the daemon/unit is enabled."""
     return action_utils.service_is_enabled(self.unit,
                                            strict_check=self.strict_check)
Esempio n. 32
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('ejabberd')
Esempio n. 33
0
def get_status(request):
    """Return the current status"""
    return {
        'restricted_access': security.get_restricted_access_enabled(),
        'fail2ban_enabled': action_utils.service_is_enabled('fail2ban')
    }
Esempio n. 34
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled('syncthing@syncthing') and
            action_utils.webserver_is_enabled('syncthing-plinth'))
Esempio n. 35
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled('transmission-daemon')
            and action_utils.webserver_is_enabled('transmission-plinth'))
Esempio n. 36
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('ejabberd')
Esempio n. 37
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.webserver_is_enabled('deluge-plinth') and
            action_utils.service_is_enabled('deluge-web'))
Esempio n. 38
0
def is_enabled():
    """Return whether the service is enabled."""
    return action_utils.service_is_enabled('repro')
Esempio n. 39
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.webserver_is_enabled('deluge-plinth')
            and action_utils.service_is_enabled('deluge-web'))
Esempio n. 40
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('avahi-daemon')
Esempio n. 41
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled('ejabberd') and
            action_utils.webserver_is_enabled('jwchat-plinth'))
Esempio n. 42
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('mumble-server')
Esempio n. 43
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('matrix-synapse')
Esempio n. 44
0
 def _default_is_enabled(self):
     """Returns is_enabled relying on a correct service_id"""
     return action_utils.service_is_enabled(self.service_id)
Esempio n. 45
0
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.service_is_enabled('syncthing@syncthing')
            and action_utils.webserver_is_enabled('syncthing-plinth'))
Esempio n. 46
0
def is_enabled():
    """Return whether the module is enabled."""
    return action_utils.service_is_enabled('node-restore')