From 1eb614081160cebbf2677bde6b02d1d6b9e7d202 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 15 Dec 2020 21:59:36 -0600 Subject: [PATCH] Added custom port and bind address args --- onionr.sh | 21 ++------------------- run-onionr-node.py | 13 +++++++++++++ src/apiservers/private/__init__.py | 11 +++++++++-- static-data/default_config.json | 1 + tests/test_default_config_json.py | 1 + 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/onionr.sh b/onionr.sh index ea925a52..0b7d898c 100755 --- a/onionr.sh +++ b/onionr.sh @@ -2,22 +2,5 @@ ORIG_ONIONR_RUN_DIR=`pwd` export ORIG_ONIONR_RUN_DIR cd "$(dirname "$0")" - -[[ -n "$USE_TOR" ]] || USE_TOR=1 -[[ -n "$PORT" ]] || PORT=8080 -[[ -n "$KEEP_LOG" ]] || KEEP_LOG=0 -[[ -n "$STORE_PLAINTEXT" ]] || STORE_PLAINTEXT=1 - -PRIVKEY_OPT="" -[[ -f "privkey.key" ]] && PRIVKEY_OPT="--private-key privkey.key" - -python run-onionr-node.py \ - --open-ui 0 \ - --onboarding 0 \ - --bind-address 0.0.0.0 \ - --port $PORT \ - --use-tor $USE_TOR \ - --keep-log-on-exit $KEEP_LOG \ - --store-plaintext $STORE_PLAINTEXT \ - $PRIVKEY_OPT \ - "$@" +cd src +./__init__.py "$@" \ No newline at end of file diff --git a/run-onionr-node.py b/run-onionr-node.py index 2c8f3431..15fd581e 100755 --- a/run-onionr-node.py +++ b/run-onionr-node.py @@ -55,6 +55,12 @@ def show_info(p: Process): parser = argparse.ArgumentParser() +parser.add_argument( + "--bind-address", help="Address to bind to. Be very careful with non-loopback", + type=str, default="") +parser.add_argument( + "--port", help="Port to bind to, must be available and possible", + type=int, default=0) parser.add_argument( "--use-bootstrap-file", help="Use bootstrap node list file", type=int, default=1) @@ -129,6 +135,13 @@ config['general']['dev_mode'] = False config['general']['store_plaintext_blocks'] = True config['general']['use_bootstrap_list'] = True config['transports']['tor'] = True +config['general']['bind_port'] = 0 # client api server port +config['general']['bind_address'] = '' # client api server address + +if args.bind_address: + config['general']['bind_address'] = args.bind_address +if args.port: + config['client']['client']['port'] = args.port if not args.use_bootstrap_file: config['general']['use_bootstrap_list'] = False diff --git a/src/apiservers/private/__init__.py b/src/apiservers/private/__init__.py index 3bc0df3a..657c30b7 100644 --- a/src/apiservers/private/__init__.py +++ b/src/apiservers/private/__init__.py @@ -50,13 +50,20 @@ class PrivateAPI: self.startTime = epoch.get_epoch() app = flask.Flask(__name__) + + bind_port = int(config.get('client.client.port', 59496)) self.bindPort = bind_port self.clientToken = config.get('client.webpassword') - self.host = httpapi.apiutils.setbindip.set_bind_IP( - private_API_host_file) + if config.get('general.bind_address'): + with open(private_API_host_file, 'w') as bindFile: + bindFile.write(config.get('general.bind_address')) + self.host = config.get('general.bind_address') + else: + self.host = httpapi.apiutils.setbindip.set_bind_IP( + private_API_host_file) logger.info('Running api on %s:%s' % (self.host, self.bindPort)) self.httpServer = '' diff --git a/static-data/default_config.json b/static-data/default_config.json index 2a788eb3..dcad2e50 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -8,6 +8,7 @@ "general": { "allow_public_api_dns_rebinding": false, "announce_node": true, + "bind_address": "", "dev_mode": false, "display_header": true, "ephemeral_tunnels": false, diff --git a/tests/test_default_config_json.py b/tests/test_default_config_json.py index b50db4b2..2678b13c 100644 --- a/tests/test_default_config_json.py +++ b/tests/test_default_config_json.py @@ -24,6 +24,7 @@ class OnionrConfig(unittest.TestCase): self.assertEqual(conf['allocations']['disk'], 1073741824) self.assertEqual(conf['allocations']['disk'], 1073741824) self.assertEqual(conf['general']['announce_node'], True) + self.assertEqual(conf['general']['bind_address'], '') self.assertEqual(conf['general']['dev_mode'], False) self.assertEqual(conf['general']['display_header'], True) self.assertEqual(conf['general']['ephemeral_tunnels'], False)