mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Don't use actions to check if service is running
- To check whether a service is running does not require root privileges. This can directly be done from a module without any action. - Since actions are allowed to be run using sudo, introducing unnecessary sub-commands increases attack surface. - Simple functions calls are unnecessarily being converted to command line invocations and involve parsing response. - There is a lot of repeated code because of this that can be eliminated. - To generalize this, we need to make all non-root system operations directly from module instead of delegating to action commands.
This commit is contained in:
1 parent
3b6af2f29c
commit
07e2c0ce14
13 files changed
+16
-71
No files matched your search
@@ -23,7 +23,10 @@ import subprocess
|
||||
|
||||
|
||||
def service_is_running(servicename):
|
||||
"""Evaluates whether a service is currently running. Returns boolean"""
|
||||
"""Return whether a service is currently running.
|
||||
|
||||
Does not need to run as root.
|
||||
"""
|
||||
try:
|
||||
subprocess.check_output(['systemctl', 'status', servicename])
|
||||
return True
|
||||
|
||||
@@ -25,6 +25,7 @@ from gettext import gettext as _
|
||||
|
||||
from .forms import DelugeForm
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
from plinth import package
|
||||
from plinth.modules import deluge
|
||||
|
||||
@@ -57,11 +58,8 @@ def get_status():
|
||||
output = actions.run('deluge', ['get-enabled'])
|
||||
enabled = (output.strip() == 'yes')
|
||||
|
||||
output = actions.run('deluge', ['is-running'])
|
||||
is_running = (output.strip() == 'yes')
|
||||
|
||||
status = {'enabled': enabled,
|
||||
'is_running': is_running}
|
||||
'is_running': action_utils.service_is_running('deluge-web')}
|
||||
|
||||
return status
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import logging
|
||||
|
||||
from .forms import MumbleForm
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
from plinth import package
|
||||
from plinth.modules import mumble
|
||||
|
||||
@@ -65,11 +66,8 @@ def get_status():
|
||||
output = actions.run('mumble', ['get-enabled'])
|
||||
enabled = (output.strip() == 'yes')
|
||||
|
||||
output = actions.superuser_run('mumble', ['is-running'])
|
||||
is_running = (output.strip() == 'yes')
|
||||
|
||||
status = {'enabled': enabled,
|
||||
'is_running': is_running}
|
||||
'is_running': action_utils.service_is_running('mumble')}
|
||||
|
||||
return status
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import logging
|
||||
import os
|
||||
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -91,8 +92,7 @@ def get_pagekite_config():
|
||||
|
||||
# PageKite service enabled/disabled
|
||||
# This assumes that if pagekite is running it's also enabled as a service
|
||||
output = run(['is-running'])
|
||||
status['enabled'] = (output.split()[0] == 'yes')
|
||||
status['enabled'] = action_utils.service_is_running('pagekite')
|
||||
|
||||
# PageKite kite details
|
||||
status.update(get_kite_details())
|
||||
|
||||
@@ -26,6 +26,7 @@ import logging
|
||||
|
||||
from .forms import PrivoxyForm
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
from plinth import package
|
||||
from plinth.modules import privoxy
|
||||
|
||||
@@ -65,11 +66,8 @@ def get_status():
|
||||
output = actions.run('privoxy', ['get-enabled'])
|
||||
enabled = (output.strip() == 'yes')
|
||||
|
||||
output = actions.superuser_run('privoxy', ['is-running'])
|
||||
is_running = (output.strip() == 'yes')
|
||||
|
||||
status = {'enabled': enabled,
|
||||
'is_running': is_running}
|
||||
'is_running': action_utils.service_is_running('privoxy')}
|
||||
|
||||
return status
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from django.template.response import TemplateResponse
|
||||
from gettext import gettext as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
|
||||
@@ -71,8 +72,6 @@ def index(request):
|
||||
|
||||
def get_status():
|
||||
"""Return the current status"""
|
||||
is_running = actions.superuser_run('tor', ['is-running']).strip() == 'yes'
|
||||
|
||||
output = actions.superuser_run('tor-get-ports')
|
||||
port_info = output.split('\n')
|
||||
ports = {}
|
||||
@@ -99,7 +98,7 @@ def get_status():
|
||||
hs_hostname = hs_info[0]
|
||||
hs_ports = hs_info[1]
|
||||
|
||||
return {'is_running': is_running,
|
||||
return {'is_running': action_utils.service_is_running('tor'),
|
||||
'ports': ports,
|
||||
'hs_enabled': hs_enabled,
|
||||
'hs_hostname': hs_hostname,
|
||||
|
||||
@@ -28,6 +28,7 @@ import socket
|
||||
|
||||
from .forms import TransmissionForm
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
from plinth import package
|
||||
from plinth.modules import transmission
|
||||
|
||||
@@ -69,15 +70,12 @@ def get_status():
|
||||
output = actions.run('transmission', ['get-enabled'])
|
||||
enabled = (output.strip() == 'yes')
|
||||
|
||||
output = actions.superuser_run('transmission', ['is-running'])
|
||||
is_running = (output.strip() == 'yes')
|
||||
|
||||
configuration = open(TRANSMISSION_CONFIG, 'r').read()
|
||||
status = json.loads(configuration)
|
||||
status = {key.translate(str.maketrans({'-': '_'})): value
|
||||
for key, value in status.items()}
|
||||
status['enabled'] = enabled
|
||||
status['is_running'] = is_running
|
||||
status['is_running'] = action_utils.service_is_running('transmission-daemon')
|
||||
status['hostname'] = socket.gethostname()
|
||||
|
||||
return status
|
||||
|
||||
Reference in new issue
Block a user