コード例 #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)
コード例 #2
0
ファイル: utils.py プロジェクト: SunilMohanAdapa/Plinth
def get_pagekite_config():
    """
    Return the current PageKite configuration by executing various actions.
    """
    status = {}

    # PageKite service enabled/disabled
    # To enable PageKite two things are necessary:
    # 1) pagekite not being disabled in /etc/pagekite.d/10_account.rc
    # 2) the pagekite service running
    is_disabled = (run(['is-disabled']).strip() == 'true')
    service_running = action_utils.service_is_running('pagekite')
    status['enabled'] = service_running and not is_disabled

    # PageKite kite details
    status.update(get_kite_details())

    # PageKite frontend server
    server = run(['get-frontend']).strip()

    # Frontend entries are only considered valid if there's a ':' in
    # them otherwise, pagekite refuses to work, and we only set values
    # with ':'.
    if ':' in server:
        server_domain, server_port = server.split(':')
        status['server_domain'] = server_domain
        status['server_port'] = int(server_port)
    else:
        status['server_domain'] = server
        # No valid entry exists, default to port 80.  Hack: Return
        # string instead of int to force setting port on save
        status['server_port'] = '80'

    return status
コード例 #3
0
def get_pagekite_config():
    """
    Return the current PageKite configuration by executing various actions.
    """
    status = {}

    # PageKite service enabled/disabled
    # To enable PageKite two things are necessary:
    # 1) pagekite not being disabled in /etc/pagekite.d/10_account.rc
    # 2) the pagekite service running
    is_disabled = (run(['is-disabled']).strip() == 'true')
    service_running = action_utils.service_is_running('pagekite')
    status['is_enabled'] = service_running and not is_disabled

    # PageKite kite details
    status.update(get_kite_details())

    # PageKite frontend server
    server = run(['get-frontend']).strip()

    # Frontend entries are only considered valid if there's a ':' in
    # them otherwise, pagekite refuses to work, and we only set values
    # with ':'.
    if ':' in server:
        server_domain, server_port = server.split(':')
        status['server_domain'] = server_domain
        status['server_port'] = int(server_port)
    else:
        status['server_domain'] = server
        # No valid entry exists, default to port 80.  Hack: Return
        # string instead of int to force setting port on save
        status['server_port'] = '80'

    return status
コード例 #4
0
ファイル: tor.py プロジェクト: nikolas/Plinth
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()}
コード例 #5
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)
コード例 #6
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'))
コード例 #7
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'))
コード例 #8
0
ファイル: test_actions.py プロジェクト: slopez15/Plinth
def try_login_to_ssh(username, password, returncode=0):
    """Return whether the sshpass returncode matches when trying to
    login to ssh using the given username and password"""
    if not action_utils.service_is_running('ssh'):
        return True

    command = [
        'sshpass', '-p', password, 'ssh', '-o', 'UserKnownHostsFile=/dev/null',
        '-o', 'StrictHostKeyChecking=no', '-o', 'VerifyHostKeyDNS=no',
        username + '@127.0.0.1', '/bin/true'
    ]
    process = subprocess.run(command, stdout=subprocess.DEVNULL,
                             stderr=subprocess.DEVNULL, check=False)
    return process.returncode == returncode
コード例 #9
0
ファイル: utils.py プロジェクト: sheelarajeshkumar/Plinth
def get_pagekite_config():
    """
    Return the current PageKite configuration by executing various actions.
    """
    status = {}

    # PageKite service enabled/disabled
    # This assumes that if pagekite is running it's also enabled as a service
    status['enabled'] = action_utils.service_is_running('pagekite')

    # PageKite kite details
    status.update(get_kite_details())

    # PageKite frontend server
    server = run(['get-frontend'])
    status['server'] = server.replace('\n', '')

    return status
コード例 #10
0
ファイル: tor.py プロジェクト: petterreinholdtsen/Plinth
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()}
コード例 #11
0
ファイル: tor.py プロジェクト: swechaFSMI/Plinth
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()}
コード例 #12
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()
    }
コード例 #13
0
ファイル: tor.py プロジェクト: petterreinholdtsen/Plinth
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)
コード例 #14
0
ファイル: tor.py プロジェクト: swechaFSMI/Plinth
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)
コード例 #15
0
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('deluge-web')
コード例 #16
0
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running(managed_services[0])
コード例 #17
0
ファイル: __init__.py プロジェクト: petterreinholdtsen/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('openvpn@freedombox')
コード例 #18
0
ファイル: __init__.py プロジェクト: gvsurenderreddy/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('avahi-daemon')
コード例 #19
0
ファイル: __init__.py プロジェクト: SunilMohanAdapa/Plinth
def is_running():
    """Return whether service is running."""
    return action_utils.service_is_running(managed_services[0])
コード例 #20
0
ファイル: __init__.py プロジェクト: bhuvi8/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('deluge-web')
コード例 #21
0
ファイル: utils.py プロジェクト: SunilMohanAdapa/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('tor@plinth')
コード例 #22
0
ファイル: __init__.py プロジェクト: sheelarajeshkumar/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running("privoxy")
コード例 #23
0
 def is_running(self):
     """Return whether the daemon/unit is running."""
     return action_utils.service_is_running(self.unit)
コード例 #24
0
ファイル: __init__.py プロジェクト: freedombox/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('syncthing@syncthing')
コード例 #25
0
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('mumble-server')
コード例 #26
0
ファイル: __init__.py プロジェクト: phylophyl/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('transmission-daemon')
コード例 #27
0
ファイル: __init__.py プロジェクト: mikini/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running("ejabberd")
コード例 #28
0
ファイル: __init__.py プロジェクト: petterreinholdtsen/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('privoxy')
コード例 #29
0
ファイル: __init__.py プロジェクト: bhuvi8/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('openvpn@freedombox')
コード例 #30
0
ファイル: __init__.py プロジェクト: gvsurenderreddy/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('repro')
コード例 #31
0
ファイル: __init__.py プロジェクト: bhuvi8/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('quasselcore')
コード例 #32
0
ファイル: __init__.py プロジェクト: nikolas/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('mumble-server')
コード例 #33
0
ファイル: __init__.py プロジェクト: SunilMohanAdapa/Plinth
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.webserver_is_enabled('cockpit-freedombox') and
            action_utils.service_is_running('cockpit.socket'))
コード例 #34
0
ファイル: service.py プロジェクト: jvalleroy/Plinth
 def is_running(self):
     if self._is_running is None:
         return action_utils.service_is_running(self.service_id)
     else:
         return self._call_or_return(self._is_running)
コード例 #35
0
ファイル: __init__.py プロジェクト: phylophyl/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('avahi-daemon')
コード例 #36
0
ファイル: __init__.py プロジェクト: sheelarajeshkumar/Plinth
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('transmission-daemon')
コード例 #37
0
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('tor@plinth')
コード例 #38
0
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('ejabberd')
コード例 #39
0
 def is_running(self):
     """Return whether the uWSGI daemon is running with configuration."""
     return action_utils.uwsgi_is_enabled(self.uwsgi_name) \
         and action_utils.service_is_running('uwsgi')
コード例 #40
0
 def stop(self):
     """Stop the service."""
     self.was_running = action_utils.service_is_running(self.service)
     if self.was_running:
         actions.superuser_run('service', ['stop', self.service])
コード例 #41
0
ファイル: __init__.py プロジェクト: vikassingh093/Plinth
def is_enabled():
    """Return whether the module is enabled."""
    return (action_utils.webserver_is_enabled('cockpit-freedombox')
            and action_utils.service_is_running('cockpit.socket'))
コード例 #42
0
def is_running():
    """Return whether the service is running."""
    return action_utils.service_is_running('syncthing@syncthing')
コード例 #43
0
ファイル: service.py プロジェクト: rajur7/Plinth
 def is_running(self):
     if self._is_running is None:
         return action_utils.service_is_running(self.service_id)
     else:
         return self._call_or_return(self._is_running)