diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index 963222fc9..bf5a8f097 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -36,11 +36,6 @@ _description = [ box_name=_(cfg.box_name)), ] -port_forwarding_info = [ - ('TCP', 53), - ('UDP', 53), -] - CONFIG_FILE = '/etc/bind/named.conf.options' ZONES_DIR = '/var/bind/pri' diff --git a/plinth/modules/bind/views.py b/plinth/modules/bind/views.py index ab0cf9a55..d244687d4 100644 --- a/plinth/modules/bind/views.py +++ b/plinth/modules/bind/views.py @@ -7,10 +7,10 @@ from django.contrib import messages from django.utils.translation import ugettext_lazy as _ from plinth import actions -from plinth.views import AppView 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 @@ -19,7 +19,6 @@ class BindAppView(AppView): # pylint: disable=too-many-ancestors app_id = 'bind' form_class = BindForm template_name = 'bind.html' - port_forwarding_info = port_forwarding_info def get_context_data(self, *args, **kwargs): """ diff --git a/plinth/modules/coturn/__init__.py b/plinth/modules/coturn/__init__.py index ba3ae9338..d5309d8f6 100644 --- a/plinth/modules/coturn/__init__.py +++ b/plinth/modules/coturn/__init__.py @@ -36,18 +36,6 @@ _description = [ '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 diff --git a/plinth/modules/coturn/views.py b/plinth/modules/coturn/views.py index 3d2b6c52d..d868a21b4 100644 --- a/plinth/modules/coturn/views.py +++ b/plinth/modules/coturn/views.py @@ -17,7 +17,6 @@ class CoturnAppView(views.AppView): app_id = 'coturn' template_name = 'coturn.html' form_class = forms.CoturnForm - port_forwarding_info = coturn.port_forwarding_info def get_context_data(self, **kwargs): """Return additional context for rendering the template.""" diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index a85bda1c8..18b66174f 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -18,10 +18,10 @@ from plinth.modules import config from plinth.modules.apache.components import Webserver from plinth.modules.firewall.components import Firewall from plinth.modules.letsencrypt.components import LetsEncrypt +from plinth.modules.users.components import UsersAndGroups from plinth.signals import (domain_added, post_hostname_change, pre_hostname_change) from plinth.utils import format_lazy -from plinth.modules.users.components import UsersAndGroups from .manifest import backup, clients # noqa, pylint: disable=unused-import @@ -46,12 +46,6 @@ _description = [ jsxc_url=reverse_lazy('jsxc:index')) ] -port_forwarding_info = [ - ('TCP', 5222), - ('TCP', 5269), - ('TCP', 5280), -] - logger = logging.getLogger(__name__) app = None diff --git a/plinth/modules/ejabberd/views.py b/plinth/modules/ejabberd/views.py index 3714ae744..d96dbf271 100644 --- a/plinth/modules/ejabberd/views.py +++ b/plinth/modules/ejabberd/views.py @@ -18,7 +18,6 @@ class EjabberdAppView(AppView): app_id = 'ejabberd' template_name = 'ejabberd.html' form_class = EjabberdForm - port_forwarding_info = ejabberd.port_forwarding_info def get_initial(self): initdict = super().get_initial() diff --git a/plinth/modules/firewall/components.py b/plinth/modules/firewall/components.py index 4519b77ac..dd721861d 100644 --- a/plinth/modules/firewall/components.py +++ b/plinth/modules/firewall/components.py @@ -149,3 +149,23 @@ class Firewall(app.FollowerComponent): results.append([message, result]) 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 diff --git a/plinth/modules/i2p/__init__.py b/plinth/modules/i2p/__init__.py index f46b1ee2b..2b2c045c7 100644 --- a/plinth/modules/i2p/__init__.py +++ b/plinth/modules/i2p/__init__.py @@ -35,12 +35,6 @@ _description = [ 'configuration process.') ] -port_forwarding_info = [ - ('TCP', 4444), - ('TCP', 4445), - ('TCP', 6668), -] - tunnels_to_manage = { 'I2P HTTP Proxy': 'i2p-http-proxy-freedombox', 'I2P HTTPS Proxy': 'i2p-https-proxy-freedombox', diff --git a/plinth/modules/i2p/views.py b/plinth/modules/i2p/views.py index c5b3bfb56..181316d1a 100644 --- a/plinth/modules/i2p/views.py +++ b/plinth/modules/i2p/views.py @@ -4,7 +4,7 @@ Views for I2P application. """ from django.utils.translation import ugettext as _ -from plinth.modules import i2p + from plinth.views import AppView @@ -29,7 +29,6 @@ class I2PAppView(AppView): def get_context_data(self, **kwargs): """Return the context data for rendering the template view.""" context = super().get_context_data(**kwargs) - context['port_forwarding_info'] = i2p.port_forwarding_info context['proxies_description'] = self.proxies_description context['torrents_description'] = self.torrents_description diff --git a/plinth/modules/infinoted/__init__.py b/plinth/modules/infinoted/__init__.py index 2624942b6..3ded41f35 100644 --- a/plinth/modules/infinoted/__init__.py +++ b/plinth/modules/infinoted/__init__.py @@ -30,8 +30,6 @@ _description = [ box_name=_(cfg.box_name)), ] -port_forwarding_info = [('TCP', 6523)] - app = None diff --git a/plinth/modules/infinoted/urls.py b/plinth/modules/infinoted/urls.py index eb1352b9c..5f67998d3 100644 --- a/plinth/modules/infinoted/urls.py +++ b/plinth/modules/infinoted/urls.py @@ -5,8 +5,9 @@ URLs for the infinoted module. from django.conf.urls import url -from .views import InfinotedAppView +from plinth.views import AppView urlpatterns = [ - url(r'^apps/infinoted/$', InfinotedAppView.as_view(), name='index'), + url(r'^apps/infinoted/$', AppView.as_view(app_id='infinoted'), + name='index'), ] diff --git a/plinth/modules/infinoted/views.py b/plinth/modules/infinoted/views.py deleted file mode 100644 index 089354e4d..000000000 --- a/plinth/modules/infinoted/views.py +++ /dev/null @@ -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 diff --git a/plinth/modules/matrixsynapse/__init__.py b/plinth/modules/matrixsynapse/__init__.py index 61307849a..99d221613 100644 --- a/plinth/modules/matrixsynapse/__init__.py +++ b/plinth/modules/matrixsynapse/__init__.py @@ -44,8 +44,6 @@ _description = [ 'Element client is recommended.') ] -port_forwarding_info = [('TCP', 8448)] - logger = logging.getLogger(__name__) SERVER_NAME_PATH = "/etc/matrix-synapse/conf.d/server_name.yaml" diff --git a/plinth/modules/matrixsynapse/views.py b/plinth/modules/matrixsynapse/views.py index c1a6e4a62..f8746b342 100644 --- a/plinth/modules/matrixsynapse/views.py +++ b/plinth/modules/matrixsynapse/views.py @@ -46,7 +46,6 @@ class MatrixSynapseAppView(AppView): app_id = 'matrixsynapse' template_name = 'matrix-synapse.html' form_class = MatrixSynapseForm - port_forwarding_info = matrixsynapse.port_forwarding_info def dispatch(self, request, *args, **kwargs): """Redirect to setup page if setup is not done yet.""" diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py index 9b8dfb435..0012e5edd 100644 --- a/plinth/modules/minetest/__init__.py +++ b/plinth/modules/minetest/__init__.py @@ -11,8 +11,8 @@ from plinth import app as app_module from plinth import cfg, frontpage, menu from plinth.daemon import Daemon from plinth.modules.firewall.components import Firewall -from plinth.utils import format_lazy from plinth.modules.users.components import UsersAndGroups +from plinth.utils import format_lazy from .manifest import backup, clients # noqa, pylint: disable=unused-import @@ -42,8 +42,6 @@ _description = [ 'is needed.'), box_name=_(cfg.box_name)), ] -port_forwarding_info = [('UDP', 30000)] - CONFIG_FILE = '/etc/minetest/minetest.conf' AUG_PATH = '/files' + CONFIG_FILE + '/.anon' diff --git a/plinth/modules/minetest/views.py b/plinth/modules/minetest/views.py index 4e4f6da63..a58dd659b 100644 --- a/plinth/modules/minetest/views.py +++ b/plinth/modules/minetest/views.py @@ -7,7 +7,7 @@ from django.contrib import messages from django.utils.translation import ugettext_lazy as _ from plinth import actions -from plinth.modules import minetest, names +from plinth.modules import names from plinth.views import AppView from . import get_configuration @@ -19,7 +19,6 @@ class MinetestAppView(AppView): # pylint: disable=too-many-ancestors app_id = 'minetest' template_name = 'minetest.html' form_class = MinetestForm - port_forwarding_info = minetest.port_forwarding_info def get_initial(self): """Return the values to fill in the form.""" diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py index 31f347ffd..2f71b3766 100644 --- a/plinth/modules/mumble/__init__.py +++ b/plinth/modules/mumble/__init__.py @@ -28,11 +28,6 @@ _description = [ 'from your desktop and Android devices are available.') ] -port_forwarding_info = [ - ('TCP', 64738), - ('UDP', 64738), -] - app = None diff --git a/plinth/modules/mumble/views.py b/plinth/modules/mumble/views.py index 55bc178f6..a12ba76ce 100644 --- a/plinth/modules/mumble/views.py +++ b/plinth/modules/mumble/views.py @@ -3,14 +3,12 @@ from django.contrib import messages from django.utils.translation import ugettext_lazy as _ from plinth import actions -from plinth.modules.mumble import port_forwarding_info from plinth.modules.mumble.forms import MumbleForm from plinth.views import AppView class MumbleAppView(AppView): app_id = 'mumble' - port_forwarding_info = port_forwarding_info form_class = MumbleForm def form_valid(self, form): diff --git a/plinth/modules/openvpn/__init__.py b/plinth/modules/openvpn/__init__.py index 978239d91..0bb5d4de8 100644 --- a/plinth/modules/openvpn/__init__.py +++ b/plinth/modules/openvpn/__init__.py @@ -32,8 +32,6 @@ _description = [ 'for added security and anonymity.'), box_name=_(cfg.box_name)) ] -port_forwarding_info = [('UDP', 1194)] - app = None setup_process = None diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py index f8e917e90..8884bfbbc 100644 --- a/plinth/modules/openvpn/views.py +++ b/plinth/modules/openvpn/views.py @@ -22,7 +22,6 @@ class OpenVPNAppView(AppView): """Show OpenVPN app main page.""" app_id = 'openvpn' template_name = 'openvpn.html' - port_forwarding_info = openvpn.port_forwarding_info def dispatch(self, request, *args, **kwargs): """Collect the result of running setup process.""" diff --git a/plinth/modules/quassel/__init__.py b/plinth/modules/quassel/__init__.py index b883fe925..bee065c40 100644 --- a/plinth/modules/quassel/__init__.py +++ b/plinth/modules/quassel/__init__.py @@ -15,8 +15,8 @@ from plinth.daemon import Daemon from plinth.modules import names from plinth.modules.firewall.components import Firewall from plinth.modules.letsencrypt.components import LetsEncrypt -from plinth.utils import format_lazy from plinth.modules.users.components import UsersAndGroups +from plinth.utils import format_lazy from .manifest import backup, clients # noqa, pylint: disable=unused-import @@ -44,8 +44,6 @@ _description = [ 'are available.'), ] -port_forwarding_info = [('TCP', 4242)] - app = None diff --git a/plinth/modules/quassel/views.py b/plinth/modules/quassel/views.py index f8266b44c..12787e0b9 100644 --- a/plinth/modules/quassel/views.py +++ b/plinth/modules/quassel/views.py @@ -11,7 +11,6 @@ from .forms import QuasselForm class QuasselAppView(AppView): app_id = 'quassel' - port_forwarding_info = quassel.port_forwarding_info form_class = QuasselForm def get_initial(self): diff --git a/plinth/modules/ssh/__init__.py b/plinth/modules/ssh/__init__.py index d66fb6f78..3657fd849 100644 --- a/plinth/modules/ssh/__init__.py +++ b/plinth/modules/ssh/__init__.py @@ -32,8 +32,6 @@ _description = [ 'using such connections.') ] -port_forwarding_info = [('TCP', 22)] - app = None diff --git a/plinth/modules/tahoe/__init__.py b/plinth/modules/tahoe/__init__.py index e8cec9501..057bd54a1 100644 --- a/plinth/modules/tahoe/__init__.py +++ b/plinth/modules/tahoe/__init__.py @@ -37,11 +37,6 @@ _description = [ 'node to the other storage nodes.'), box_name=_(cfg.box_name)), ] -port_forwarding_info = [ - ('TCP', 3456), - ('TCP', 5678), -] - tahoe_home = '/var/lib/tahoe-lafs' introducer_name = 'introducer' storage_node_name = 'storage_node' diff --git a/plinth/modules/tahoe/views.py b/plinth/modules/tahoe/views.py index 4ddec91eb..82bfd6510 100644 --- a/plinth/modules/tahoe/views.py +++ b/plinth/modules/tahoe/views.py @@ -36,7 +36,6 @@ class TahoeAppView(AppView): """Show tahoe-lafs service page.""" app_id = 'tahoe' template_name = 'tahoe-post-setup.html' - port_forwarding_info = tahoe.port_forwarding_info def dispatch(self, request, *args, **kwargs): if not tahoe.is_setup(): diff --git a/plinth/modules/wireguard/__init__.py b/plinth/modules/wireguard/__init__.py index 771813a49..210bd216f 100644 --- a/plinth/modules/wireguard/__init__.py +++ b/plinth/modules/wireguard/__init__.py @@ -33,8 +33,6 @@ _description = [ box_name=_(cfg.box_name)) ] -port_forwarding_info = [('UDP', 51820)] - app = None SERVER_INTERFACE = 'wg0' diff --git a/plinth/modules/wireguard/views.py b/plinth/modules/wireguard/views.py index 43dbf3f75..1a4aabc31 100644 --- a/plinth/modules/wireguard/views.py +++ b/plinth/modules/wireguard/views.py @@ -13,7 +13,6 @@ from django.urls import reverse_lazy from django.utils.translation import ugettext as _ from django.views.generic import FormView, TemplateView -import plinth.modules.wireguard as wireguard from plinth import network from plinth.modules.names.components import DomainName from plinth.views import AppView @@ -26,7 +25,6 @@ class WireguardView(AppView): app_id = 'wireguard' diagnostics_module_name = 'wireguard' template_name = 'wireguard.html' - port_forwarding_info = wireguard.port_forwarding_info def get_context_data(self, **kwargs): """Return additional context for rendering the template.""" diff --git a/plinth/views.py b/plinth/views.py index d61e79356..4b8570ca7 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -19,6 +19,7 @@ from stronghold.decorators import public from plinth import app, package from plinth.daemon import app_is_running 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 . import forms, frontpage @@ -146,15 +147,10 @@ class AppView(FormView): to customize the appearance of the app to achieve more complex presentation 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 app_id = None template_name = 'app.html' - port_forwarding_info = None def __init__(self, *args, **kwargs): """Initialize the view.""" @@ -254,7 +250,7 @@ class AppView(FormView): context['is_running'] = app_is_running(self.app) context['app_info'] = self.app.info 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() from plinth.modules.firewall.components import Firewall