From 5c26c28f96470a3b321b5d610a39eee5a3d1c56c Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Mon, 8 Apr 2019 20:13:16 +0200 Subject: [PATCH] i2p: Open HTTP(S) and IRC ports on all interfaces on install I2P has to be restarted in order for the changes to take effect. Reviewed-by: Sunil Mohan Adapa --- actions/i2p | 25 +++++++++++++++++++++++++ plinth/modules/i2p/__init__.py | 16 +++++++++++++++- plinth/modules/i2p/helpers.py | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/actions/i2p b/actions/i2p index 9bdaacefe..e120bc96b 100755 --- a/actions/i2p +++ b/actions/i2p @@ -23,6 +23,7 @@ import argparse import os from plinth import action_utils, cfg +from plinth.modules.i2p.helpers import TunnelEditor cfg.read() module_config_path = os.path.join(cfg.config_dir, 'modules-enabled') @@ -43,6 +44,12 @@ def parse_arguments(): subparser.add_argument('--name', help='Name of the entry', required=True) subparser.add_argument('--url', help='URL of the entry', required=True) + subparser = subparsers.add_parser( + 'set-tunnel-property', help='Modify configuration of a tunnel') + subparser.add_argument('--name', help='Name of the tunnel', required=True) + subparser.add_argument('--property', help='Property to modify', required=True) + subparser.add_argument('--value', help='Value to assign', required=True) + subparsers.required = True return parser.parse_args() @@ -59,6 +66,24 @@ def subcommand_disable(_): action_utils.webserver_disable('i2p-freedombox') +def subcommand_set_tunnel_property(arguments): + """ + Modifies the configuration for a certain tunnel + """ + + editor = TunnelEditor() + editor \ + .read_conf() \ + .set_tunnel_idx(arguments.name) \ + .set_tunnel_prop(arguments.property, arguments.value) \ + .write_conf() + print('Updated "{property}" of {filename} to {value}'.format( + property=editor.calc_prop_path(arguments.property), + filename=editor.conf_filename, + value=arguments.value + )) + + def subcommand_add_favorite(arguments): """ Adds a favorite to the router.config diff --git a/plinth/modules/i2p/__init__.py b/plinth/modules/i2p/__init__.py index 33ca296bf..e8fc6aa8c 100644 --- a/plinth/modules/i2p/__init__.py +++ b/plinth/modules/i2p/__init__.py @@ -24,7 +24,6 @@ from plinth import action_utils, actions, frontpage from plinth import service as service_module from plinth.menu import main_menu from plinth.modules.users import register_group - from .manifest import backup, clients version = 1 @@ -65,6 +64,12 @@ additional_favorites = [ ('YaCy Seeker', 'http://seeker.i2p'), ] +tunnels_to_manage = [ + 'I2P HTTP Proxy', + 'I2P HTTPS Proxy', + 'Irc2P' +] + def init(): """Intialize the module.""" @@ -98,6 +103,15 @@ def setup(helper, old_version=None): '--url', fav_url, ]) + + # Tunnels to all interfaces + for tunnel in tunnels_to_manage: + helper.call('post', actions.superuser_run, 'i2p', [ + 'set-tunnel-property', + '--name', tunnel, + '--property', 'interface', + '--value', '0.0.0.0' + ]) helper.call('post', enable) global service if service is None: diff --git a/plinth/modules/i2p/helpers.py b/plinth/modules/i2p/helpers.py index 76b1301cd..48703fae7 100644 --- a/plinth/modules/i2p/helpers.py +++ b/plinth/modules/i2p/helpers.py @@ -71,7 +71,7 @@ class TunnelEditor(object): if match and self.aug.get(prop) == name: self.idx = int(match.group(1)) return self - raise ValueError('No tunnel with that name') + raise ValueError('No tunnel called {}'.format(name)) def calc_prop_path(self, tunnel_prop): """