firewall: Use service files for showing port forwarding info

- Start showing port ranges properly.

- Fixes issue with Coturn TURN relay ports not being shown.

Closes: #1851.

Tests:

- Visit each of affected apps and see the port forwarding information. The
information is same as before.

- HTTP and HTTPS ports are not shown.

- Coturn app shows additional port ranges for TURN relay ports.

- Shadowsocks app does not show port forwarding information as it is internal
only.

- Visit one of the apps not effected by the patch. There is no section related
to port forwarding.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2020-09-01 22:11:28 -07:00 committed by Veiko Aasa
parent c218f3845f
commit 4aa8e6da09
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
28 changed files with 32 additions and 93 deletions

View File

@ -36,11 +36,6 @@ _description = [
box_name=_(cfg.box_name)), box_name=_(cfg.box_name)),
] ]
port_forwarding_info = [
('TCP', 53),
('UDP', 53),
]
CONFIG_FILE = '/etc/bind/named.conf.options' CONFIG_FILE = '/etc/bind/named.conf.options'
ZONES_DIR = '/var/bind/pri' ZONES_DIR = '/var/bind/pri'

View File

@ -7,10 +7,10 @@ from django.contrib import messages
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from plinth import actions from plinth import actions
from plinth.views import AppView
from plinth.modules import bind, names from plinth.modules import bind, names
from plinth.views import AppView
from . import get_config, port_forwarding_info from . import get_config
from .forms import BindForm from .forms import BindForm
@ -19,7 +19,6 @@ class BindAppView(AppView): # pylint: disable=too-many-ancestors
app_id = 'bind' app_id = 'bind'
form_class = BindForm form_class = BindForm
template_name = 'bind.html' template_name = 'bind.html'
port_forwarding_info = port_forwarding_info
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
""" """

View File

@ -36,18 +36,6 @@ _description = [
'matrix-synapse need to be configured with the details provided here.'), 'matrix-synapse need to be configured with the details provided here.'),
] ]
port_forwarding_info = [
('UDP', 3478),
('TCP', 3478),
('UDP', 3479),
('TCP', 3479),
('UDP', 5349),
('TCP', 5349),
('UDP', 5350),
('TCP', 5350),
# XXX: Add relay ports here
]
app = None app = None

View File

@ -17,7 +17,6 @@ class CoturnAppView(views.AppView):
app_id = 'coturn' app_id = 'coturn'
template_name = 'coturn.html' template_name = 'coturn.html'
form_class = forms.CoturnForm form_class = forms.CoturnForm
port_forwarding_info = coturn.port_forwarding_info
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Return additional context for rendering the template.""" """Return additional context for rendering the template."""

View File

@ -18,10 +18,10 @@ from plinth.modules import config
from plinth.modules.apache.components import Webserver from plinth.modules.apache.components import Webserver
from plinth.modules.firewall.components import Firewall from plinth.modules.firewall.components import Firewall
from plinth.modules.letsencrypt.components import LetsEncrypt from plinth.modules.letsencrypt.components import LetsEncrypt
from plinth.modules.users.components import UsersAndGroups
from plinth.signals import (domain_added, post_hostname_change, from plinth.signals import (domain_added, post_hostname_change,
pre_hostname_change) pre_hostname_change)
from plinth.utils import format_lazy from plinth.utils import format_lazy
from plinth.modules.users.components import UsersAndGroups
from .manifest import backup, clients # noqa, pylint: disable=unused-import from .manifest import backup, clients # noqa, pylint: disable=unused-import
@ -46,12 +46,6 @@ _description = [
jsxc_url=reverse_lazy('jsxc:index')) jsxc_url=reverse_lazy('jsxc:index'))
] ]
port_forwarding_info = [
('TCP', 5222),
('TCP', 5269),
('TCP', 5280),
]
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
app = None app = None

View File

@ -18,7 +18,6 @@ class EjabberdAppView(AppView):
app_id = 'ejabberd' app_id = 'ejabberd'
template_name = 'ejabberd.html' template_name = 'ejabberd.html'
form_class = EjabberdForm form_class = EjabberdForm
port_forwarding_info = ejabberd.port_forwarding_info
def get_initial(self): def get_initial(self):
initdict = super().get_initial() initdict = super().get_initial()

View File

@ -149,3 +149,23 @@ class Firewall(app.FollowerComponent):
results.append([message, result]) results.append([message, result])
return results return results
def get_port_forwarding_info(app_):
"""Return a list of ports to be forwarded for this app to work."""
info = []
for component in app_.components.values():
if not isinstance(component, Firewall):
continue
if not component.is_external:
continue
for port in component.ports_details:
if port['name'] in ['http', 'https']:
continue
for detail in port['details']:
info.append((detail[1].upper(), detail[0]))
return info

View File

@ -35,12 +35,6 @@ _description = [
'configuration process.') 'configuration process.')
] ]
port_forwarding_info = [
('TCP', 4444),
('TCP', 4445),
('TCP', 6668),
]
tunnels_to_manage = { tunnels_to_manage = {
'I2P HTTP Proxy': 'i2p-http-proxy-freedombox', 'I2P HTTP Proxy': 'i2p-http-proxy-freedombox',
'I2P HTTPS Proxy': 'i2p-https-proxy-freedombox', 'I2P HTTPS Proxy': 'i2p-https-proxy-freedombox',

View File

@ -4,7 +4,7 @@ Views for I2P application.
""" """
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from plinth.modules import i2p
from plinth.views import AppView from plinth.views import AppView
@ -29,7 +29,6 @@ class I2PAppView(AppView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view.""" """Return the context data for rendering the template view."""
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['port_forwarding_info'] = i2p.port_forwarding_info
context['proxies_description'] = self.proxies_description context['proxies_description'] = self.proxies_description
context['torrents_description'] = self.torrents_description context['torrents_description'] = self.torrents_description

View File

@ -30,8 +30,6 @@ _description = [
box_name=_(cfg.box_name)), box_name=_(cfg.box_name)),
] ]
port_forwarding_info = [('TCP', 6523)]
app = None app = None

View File

@ -5,8 +5,9 @@ URLs for the infinoted module.
from django.conf.urls import url from django.conf.urls import url
from .views import InfinotedAppView from plinth.views import AppView
urlpatterns = [ urlpatterns = [
url(r'^apps/infinoted/$', InfinotedAppView.as_view(), name='index'), url(r'^apps/infinoted/$', AppView.as_view(app_id='infinoted'),
name='index'),
] ]

View File

@ -1,12 +0,0 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Views for the infinoted app.
"""
from plinth.modules import infinoted
from plinth.views import AppView
class InfinotedAppView(AppView):
"""Main app view for Infinoted."""
app_id = 'infinoted'
port_forwarding_info = infinoted.port_forwarding_info

View File

@ -44,8 +44,6 @@ _description = [
'<a href="https://element.io/">Element</a> client is recommended.') '<a href="https://element.io/">Element</a> client is recommended.')
] ]
port_forwarding_info = [('TCP', 8448)]
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
SERVER_NAME_PATH = "/etc/matrix-synapse/conf.d/server_name.yaml" SERVER_NAME_PATH = "/etc/matrix-synapse/conf.d/server_name.yaml"

View File

@ -46,7 +46,6 @@ class MatrixSynapseAppView(AppView):
app_id = 'matrixsynapse' app_id = 'matrixsynapse'
template_name = 'matrix-synapse.html' template_name = 'matrix-synapse.html'
form_class = MatrixSynapseForm form_class = MatrixSynapseForm
port_forwarding_info = matrixsynapse.port_forwarding_info
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
"""Redirect to setup page if setup is not done yet.""" """Redirect to setup page if setup is not done yet."""

View File

@ -11,8 +11,8 @@ from plinth import app as app_module
from plinth import cfg, frontpage, menu from plinth import cfg, frontpage, menu
from plinth.daemon import Daemon from plinth.daemon import Daemon
from plinth.modules.firewall.components import Firewall from plinth.modules.firewall.components import Firewall
from plinth.utils import format_lazy
from plinth.modules.users.components import UsersAndGroups from plinth.modules.users.components import UsersAndGroups
from plinth.utils import format_lazy
from .manifest import backup, clients # noqa, pylint: disable=unused-import from .manifest import backup, clients # noqa, pylint: disable=unused-import
@ -42,8 +42,6 @@ _description = [
'is needed.'), box_name=_(cfg.box_name)), 'is needed.'), box_name=_(cfg.box_name)),
] ]
port_forwarding_info = [('UDP', 30000)]
CONFIG_FILE = '/etc/minetest/minetest.conf' CONFIG_FILE = '/etc/minetest/minetest.conf'
AUG_PATH = '/files' + CONFIG_FILE + '/.anon' AUG_PATH = '/files' + CONFIG_FILE + '/.anon'

View File

@ -7,7 +7,7 @@ from django.contrib import messages
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from plinth import actions from plinth import actions
from plinth.modules import minetest, names from plinth.modules import names
from plinth.views import AppView from plinth.views import AppView
from . import get_configuration from . import get_configuration
@ -19,7 +19,6 @@ class MinetestAppView(AppView): # pylint: disable=too-many-ancestors
app_id = 'minetest' app_id = 'minetest'
template_name = 'minetest.html' template_name = 'minetest.html'
form_class = MinetestForm form_class = MinetestForm
port_forwarding_info = minetest.port_forwarding_info
def get_initial(self): def get_initial(self):
"""Return the values to fill in the form.""" """Return the values to fill in the form."""

View File

@ -28,11 +28,6 @@ _description = [
'from your desktop and Android devices are available.') 'from your desktop and Android devices are available.')
] ]
port_forwarding_info = [
('TCP', 64738),
('UDP', 64738),
]
app = None app = None

View File

@ -3,14 +3,12 @@ from django.contrib import messages
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from plinth import actions from plinth import actions
from plinth.modules.mumble import port_forwarding_info
from plinth.modules.mumble.forms import MumbleForm from plinth.modules.mumble.forms import MumbleForm
from plinth.views import AppView from plinth.views import AppView
class MumbleAppView(AppView): class MumbleAppView(AppView):
app_id = 'mumble' app_id = 'mumble'
port_forwarding_info = port_forwarding_info
form_class = MumbleForm form_class = MumbleForm
def form_valid(self, form): def form_valid(self, form):

View File

@ -32,8 +32,6 @@ _description = [
'for added security and anonymity.'), box_name=_(cfg.box_name)) 'for added security and anonymity.'), box_name=_(cfg.box_name))
] ]
port_forwarding_info = [('UDP', 1194)]
app = None app = None
setup_process = None setup_process = None

View File

@ -22,7 +22,6 @@ class OpenVPNAppView(AppView):
"""Show OpenVPN app main page.""" """Show OpenVPN app main page."""
app_id = 'openvpn' app_id = 'openvpn'
template_name = 'openvpn.html' template_name = 'openvpn.html'
port_forwarding_info = openvpn.port_forwarding_info
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
"""Collect the result of running setup process.""" """Collect the result of running setup process."""

View File

@ -15,8 +15,8 @@ from plinth.daemon import Daemon
from plinth.modules import names from plinth.modules import names
from plinth.modules.firewall.components import Firewall from plinth.modules.firewall.components import Firewall
from plinth.modules.letsencrypt.components import LetsEncrypt from plinth.modules.letsencrypt.components import LetsEncrypt
from plinth.utils import format_lazy
from plinth.modules.users.components import UsersAndGroups from plinth.modules.users.components import UsersAndGroups
from plinth.utils import format_lazy
from .manifest import backup, clients # noqa, pylint: disable=unused-import from .manifest import backup, clients # noqa, pylint: disable=unused-import
@ -44,8 +44,6 @@ _description = [
'are available.'), 'are available.'),
] ]
port_forwarding_info = [('TCP', 4242)]
app = None app = None

View File

@ -11,7 +11,6 @@ from .forms import QuasselForm
class QuasselAppView(AppView): class QuasselAppView(AppView):
app_id = 'quassel' app_id = 'quassel'
port_forwarding_info = quassel.port_forwarding_info
form_class = QuasselForm form_class = QuasselForm
def get_initial(self): def get_initial(self):

View File

@ -32,8 +32,6 @@ _description = [
'using such connections.') 'using such connections.')
] ]
port_forwarding_info = [('TCP', 22)]
app = None app = None

View File

@ -37,11 +37,6 @@ _description = [
'node to the other storage nodes.'), box_name=_(cfg.box_name)), 'node to the other storage nodes.'), box_name=_(cfg.box_name)),
] ]
port_forwarding_info = [
('TCP', 3456),
('TCP', 5678),
]
tahoe_home = '/var/lib/tahoe-lafs' tahoe_home = '/var/lib/tahoe-lafs'
introducer_name = 'introducer' introducer_name = 'introducer'
storage_node_name = 'storage_node' storage_node_name = 'storage_node'

View File

@ -36,7 +36,6 @@ class TahoeAppView(AppView):
"""Show tahoe-lafs service page.""" """Show tahoe-lafs service page."""
app_id = 'tahoe' app_id = 'tahoe'
template_name = 'tahoe-post-setup.html' template_name = 'tahoe-post-setup.html'
port_forwarding_info = tahoe.port_forwarding_info
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if not tahoe.is_setup(): if not tahoe.is_setup():

View File

@ -33,8 +33,6 @@ _description = [
box_name=_(cfg.box_name)) box_name=_(cfg.box_name))
] ]
port_forwarding_info = [('UDP', 51820)]
app = None app = None
SERVER_INTERFACE = 'wg0' SERVER_INTERFACE = 'wg0'

View File

@ -13,7 +13,6 @@ from django.urls import reverse_lazy
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.generic import FormView, TemplateView from django.views.generic import FormView, TemplateView
import plinth.modules.wireguard as wireguard
from plinth import network from plinth import network
from plinth.modules.names.components import DomainName from plinth.modules.names.components import DomainName
from plinth.views import AppView from plinth.views import AppView
@ -26,7 +25,6 @@ class WireguardView(AppView):
app_id = 'wireguard' app_id = 'wireguard'
diagnostics_module_name = 'wireguard' diagnostics_module_name = 'wireguard'
template_name = 'wireguard.html' template_name = 'wireguard.html'
port_forwarding_info = wireguard.port_forwarding_info
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Return additional context for rendering the template.""" """Return additional context for rendering the template."""

View File

@ -19,6 +19,7 @@ from stronghold.decorators import public
from plinth import app, package from plinth import app, package
from plinth.daemon import app_is_running from plinth.daemon import app_is_running
from plinth.modules.config import get_advanced_mode from plinth.modules.config import get_advanced_mode
from plinth.modules.firewall.components import get_port_forwarding_info
from plinth.translation import get_language_from_request, set_language from plinth.translation import get_language_from_request, set_language
from . import forms, frontpage from . import forms, frontpage
@ -146,15 +147,10 @@ class AppView(FormView):
to customize the appearance of the app to achieve more complex presentation to customize the appearance of the app to achieve more complex presentation
instead of the simple appearance provided by default. instead of the simple appearance provided by default.
'port_forwarding_info' is a list of port information dictionaries that can
used to show a special section in the app page that tells the users how to
forward ports on their router for this app to work properly.
""" """
form_class = None form_class = None
app_id = None app_id = None
template_name = 'app.html' template_name = 'app.html'
port_forwarding_info = None
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Initialize the view.""" """Initialize the view."""
@ -254,7 +250,7 @@ class AppView(FormView):
context['is_running'] = app_is_running(self.app) context['is_running'] = app_is_running(self.app)
context['app_info'] = self.app.info context['app_info'] = self.app.info
context['has_diagnostics'] = self.app.has_diagnostics() context['has_diagnostics'] = self.app.has_diagnostics()
context['port_forwarding_info'] = self.port_forwarding_info context['port_forwarding_info'] = get_port_forwarding_info(self.app)
context['app_enable_disable_form'] = self.get_enable_disable_form() context['app_enable_disable_form'] = self.get_enable_disable_form()
from plinth.modules.firewall.components import Firewall from plinth.modules.firewall.components import Firewall