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
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user