[#759] Add fail2ban to Plinth UI

Run sudo-required action via actions.superuser_run

Actions related to services those require `sudo` permissions need to
be executed via actions.superuser_run.

NOTE:
If plinth service is started via `sudo ./run --debug` (in dev mode)
all actions will be executed silently. But plinth in user machines
won't be executed with sudo permissions.
This commit is contained in:
nsaikiran authored and James Valleroy committed 2017-07-29 09:42:31 -04:00
1 parent 09f3f23e10
commit a8a5da996e
5 files changed
+42 -2

No files matched your search

+15 -1
View File
@@ -25,12 +25,15 @@ from plinth import actions
from plinth.menu import main_menu
version = 1
version = 2
is_essential = True
title = _('Security')
managed_packages = ['fail2ban']
managed_services = ['fail2ban']
ACCESS_CONF_FILE = '/etc/security/access.conf'
ACCESS_CONF_SNIPPET = '-:ALL EXCEPT root fbx (admin) (sudo):ALL'
@@ -42,6 +45,17 @@ def init():
menu.add_urlname(title, 'glyphicon-lock', 'security:index')
def setup(helper, old_version=None):
"""Install the required packages"""
helper.install(managed_packages)
setup_fail2ban()
def setup_fail2ban():
actions.superuser_run('service', ['unmask', 'fail2ban'])
actions.superuser_run('service', ['enable', 'fail2ban'])
def get_restricted_access_enabled():
"""Return whether restricted access is enabled"""
with open(ACCESS_CONF_FILE, 'r') as conffile: