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
@@ -65,10 +65,6 @@ def parse_arguments():
|
||||
# Disable deluge-web site and stop deluge-web
|
||||
subparsers.add_parser('disable', help='Disable deluge-web site')
|
||||
|
||||
# Get whether deluge-web is running
|
||||
subparsers.add_parser('is-running',
|
||||
help='Get whether deluge-web is running')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -94,11 +90,6 @@ def subcommand_disable(_):
|
||||
disable()
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Get whether deluge-web is running."""
|
||||
print('yes' if action_utils.service_is_running('deluge-web') else 'no')
|
||||
|
||||
|
||||
def enable():
|
||||
"""Start and enable deluge-web service."""
|
||||
action_utils.service_enable('deluge-web')
|
||||
|
||||
@@ -45,10 +45,6 @@ def parse_arguments():
|
||||
# Disable service
|
||||
subparsers.add_parser('disable', help='Disable Mumble service')
|
||||
|
||||
# Get whether daemon is running
|
||||
subparsers.add_parser('is-running',
|
||||
help='Get whether Mumble daemon is running')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -95,11 +91,6 @@ def set_service_enable(enable):
|
||||
file.writelines(lines)
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Get whether server is running."""
|
||||
print('yes' if action_utils.service_is_running('mumble-server') else 'no')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@@ -49,7 +49,6 @@ def parse_arguments():
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Enable/disable the pagekite service
|
||||
subparsers.add_parser('is-running', help='Get whether PakeKite is running')
|
||||
subparsers.add_parser('start-and-enable', help='Enable PageKite service')
|
||||
subparsers.add_parser('stop-and-disable', help='Disable PageKite service')
|
||||
subparsers.add_parser('restart', help='Restart PageKite service')
|
||||
@@ -81,11 +80,6 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Print whether pagekite is enabled (yes or no)"""
|
||||
print('yes' if action_utils.service_is_running('pagekite') else 'no')
|
||||
|
||||
|
||||
def subcommand_restart(_):
|
||||
"""Restart the pagekite service"""
|
||||
action_utils.service_restart('pagekite')
|
||||
|
||||
@@ -41,8 +41,6 @@ def parse_arguments():
|
||||
help='Get whether Privoxy service is enabled')
|
||||
subparsers.add_parser('enable', help='Enable Privoxy service')
|
||||
subparsers.add_parser('disable', help='Disable Privoxy service')
|
||||
subparsers.add_parser('is-running',
|
||||
help='Get whether Privoxy daemon is running')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -83,12 +81,6 @@ def subcommand_disable(_):
|
||||
action_utils.service_disable('privoxy')
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Get whether server is running."""
|
||||
running = action_utils.service_is_running('privoxy')
|
||||
print('yes' if running else 'no')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@@ -34,9 +34,6 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Get whether Tor is running
|
||||
subparsers.add_parser('is-running', help='Get whether Tor is running')
|
||||
|
||||
# Enable and start the service
|
||||
subparsers.add_parser('enable', help='Enable and start Tor service')
|
||||
|
||||
@@ -55,11 +52,6 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Get whether Tor is running"""
|
||||
print('yes' if action_utils.service_is_running('tor') else 'no')
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Enable and start the service."""
|
||||
action_utils.service_enable('tor')
|
||||
|
||||
@@ -47,10 +47,6 @@ def parse_arguments():
|
||||
# Disable service
|
||||
subparsers.add_parser('disable', help='Disable Transmission service')
|
||||
|
||||
# Get whether daemon is running
|
||||
subparsers.add_parser('is-running',
|
||||
help='Get whether Transmission daemon is running')
|
||||
|
||||
# Merge given JSON configration with existing
|
||||
merge_configuration = subparsers.add_parser(
|
||||
'merge-configuration',
|
||||
@@ -108,11 +104,6 @@ def set_service_enable(enable):
|
||||
file_handle.writelines(lines)
|
||||
|
||||
|
||||
def subcommand_is_running(_):
|
||||
"""Get whether Transmission is running."""
|
||||
print('yes' if action_utils.service_is_running('transmission-daemon') else 'no')
|
||||
|
||||
|
||||
def subcommand_merge_configuration(arguments):
|
||||
"""Merge given JSON configuration with existing configuration."""
|
||||
configuration = arguments.configuration
|
||||
|
||||
Reference in new issue
Block a user