diff --git a/actions/tor b/actions/tor index d26b0bce4..e08781811 100755 --- a/actions/tor +++ b/actions/tor @@ -39,6 +39,7 @@ def parse_arguments(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') + subparsers.add_parser('setup', help='Setup Tor configuration') subparsers.add_parser('enable', help='Enable and start Tor service') subparsers.add_parser('disable', help='Disable and stop Tor service') subparsers.add_parser('get-hs', help='Get hidden service') @@ -49,6 +50,41 @@ def parse_arguments(): return parser.parse_args() +def subcommand_setup(_): + """Setup Tor configuration after installing it.""" + # XXX: Performing this as a post-install step instead of + # pre-install setup for now. Creating a configuration before hand + # leads dpkg to ask question about configuration overwrite which + # makes aptcc backend of packagekit to wait forever even with + # interactive=False. + lines = """ +# Run as non-exit bridge relay +SocksPort [::]:9050 +SocksPort 0.0.0.0:9050 +ORPort auto +ControlPort 9051 +BridgeRelay 1 +Exitpolicy reject *:* +Exitpolicy reject6 *:* + +# Enable obfsproxy +ServerTransportPlugin obfs3,scramblesuit exec /usr/bin/obfsproxy managed +ExtORPort auto + +# Enable transparent proxy +VirtualAddrNetworkIPv4 10.192.0.0/10 +AutomapHostsOnResolve 1 +TransPort 127.0.0.1:9040 +TransPort [::1]:9040 +DNSPort 127.0.0.1:9053 +DNSPort [::1]:9053 +""" + with open(TOR_CONFIG, 'w') as conffile: + conffile.writelines(lines) + + action_utils.service_restart('tor') + + def subcommand_enable(_): """Enable and start the service.""" action_utils.service_enable('tor') diff --git a/plinth/modules/tor/tor.py b/plinth/modules/tor/tor.py index d87099bc1..5fae309df 100644 --- a/plinth/modules/tor/tor.py +++ b/plinth/modules/tor/tor.py @@ -50,7 +50,12 @@ def init(): 'tor:index', 100) -@package.required(['tor']) +def on_install(): + """Setup Tor configuration as soon as it is installed.""" + actions.superuser_run('tor', ['setup']) + + +@package.required(['tor', 'obfsproxy'], on_install=on_install) def index(request): """Service the index page""" status = get_status() diff --git a/plinth/package.py b/plinth/package.py index 92c968f29..2c7b6d91a 100644 --- a/plinth/package.py +++ b/plinth/package.py @@ -263,7 +263,8 @@ def _should_show_install_view(request, package_names): return False else: messages.error(request, _('Error installing packages: {details}') - .format(details=exception.error_string)) + .format(details=getattr(exception, 'error_string', + str(exception)))) return True