From e03dc1a42f3f1055c1ccc803ac8913714e4214a4 Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Sat, 7 May 2022 21:44:28 -0400 Subject: [PATCH 1/5] Add host specification on the CLI for #763 --- ipwb/__main__.py | 12 +++++++++++- ipwb/replay.py | 8 ++++---- ipwb/util.py | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ipwb/__main__.py b/ipwb/__main__.py index 84201529..7b384c93 100644 --- a/ipwb/__main__.py +++ b/ipwb/__main__.py @@ -58,6 +58,11 @@ def check_args_replay(args): print(f'Proxying to {args.proxy}') proxy = args.proxy + host = replay.IPWBREPLAY_HOST + if hasattr(args, 'host') and args.host is not None: + print(f'Using custom host {args.host} for replay.') + host = args.host + port = replay.IPWBREPLAY_PORT if hasattr(args, 'port') and args.port is not None: print(f'Using custom port {args.port} for replay.') @@ -65,7 +70,7 @@ def check_args_replay(args): # TODO: add any other sub-arguments for replay here if supplied_index_parameter: - replay.start(cdxj_file_path=args.index, proxy=proxy, port=port) + replay.start(cdxj_file_path=args.index, proxy=proxy, host=host, port=port) else: print('ERROR: An index file must be specified if not piping, e.g.,') print(("> ipwb replay " @@ -144,6 +149,11 @@ def check_args(args_in): type=int, default=util.IPWBREPLAY_PORT ) + replay_parser.add_argument( + '-H', '--host', + help='Custom Host', + default=util.IPWBREPLAY_HOST + ) replay_parser.set_defaults(func=check_args_replay, onError=replay_parser.print_help) diff --git a/ipwb/replay.py b/ipwb/replay.py index d83fa427..8e2e3d05 100755 --- a/ipwb/replay.py +++ b/ipwb/replay.py @@ -1047,15 +1047,15 @@ def get_cdxj_line_binary_search( return line_found -def start(cdxj_file_path, proxy=None, port=IPWBREPLAY_PORT): +def start(cdxj_file_path, proxy=None, host=IPWBREPLAY_HOST, port=IPWBREPLAY_PORT): host_port = ipwb_utils.get_ipwb_replay_config() app.proxy = proxy # Retain port for subsequent runs - ipwb_utils.set_ipwb_replay_config(IPWBREPLAY_HOST, port) + ipwb_utils.set_ipwb_replay_config(host, port) if not host_port: - host_port = (IPWBREPLAY_HOST, port) + host_port = (host, port) # This will throw an exception if daemon is not available. ipwb_utils.check_daemon_is_alive() @@ -1067,7 +1067,7 @@ def start(cdxj_file_path, proxy=None, port=IPWBREPLAY_PORT): print((f'IPWB replay started on ' f'http://{host_port[0]}:{host_port[1]}')) - app.run(host='0.0.0.0', port=host_port[1]) + app.run(host=host_and_port[0], port=host_port[1]) except gaierror: print('Detected no active Internet connection.') print('Overriding to use default IP and port configuration.') diff --git a/ipwb/util.py b/ipwb/util.py index dbbf12b6..d220e011 100644 --- a/ipwb/util.py +++ b/ipwb/util.py @@ -33,7 +33,7 @@ # or '/ip4/{ipaddress}/tcp/{port}/http' # or '/ip6/{ipaddress}/tcp/{port}/http -IPWBREPLAY_ADDRESS = 'localhost:2016' +IPWBREPLAY_ADDRESS = '0.0.0.0:2016' (IPWBREPLAY_HOST, IPWBREPLAY_PORT) = IPWBREPLAY_ADDRESS.split(':') IPWBREPLAY_PORT = int(IPWBREPLAY_PORT) From 6c8260db4802ebd61764a92815c5dca10bcfc0d5 Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Sat, 7 May 2022 22:10:44 -0400 Subject: [PATCH 2/5] Switch order of host/port flags in replay help --- ipwb/__main__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ipwb/__main__.py b/ipwb/__main__.py index 7b384c93..c34fcda6 100644 --- a/ipwb/__main__.py +++ b/ipwb/__main__.py @@ -143,17 +143,18 @@ def check_args(args_in): help='Proxy URL', metavar='', nargs='?') + replay_parser.add_argument( + '-H', '--host', + help='Custom Host', + default=util.IPWBREPLAY_HOST + ) replay_parser.add_argument( '-p', '--port', help='Custom Port', type=int, default=util.IPWBREPLAY_PORT ) - replay_parser.add_argument( - '-H', '--host', - help='Custom Host', - default=util.IPWBREPLAY_HOST - ) + replay_parser.set_defaults(func=check_args_replay, onError=replay_parser.print_help) From 4176afc2777d415a0998a7d48721f58caa52b0be Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Sat, 7 May 2022 22:14:38 -0400 Subject: [PATCH 3/5] Fix varname typo --- ipwb/replay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipwb/replay.py b/ipwb/replay.py index 8e2e3d05..c7ece0ea 100755 --- a/ipwb/replay.py +++ b/ipwb/replay.py @@ -1067,7 +1067,7 @@ def start(cdxj_file_path, proxy=None, host=IPWBREPLAY_HOST, port=IPWBREPLAY_PORT print((f'IPWB replay started on ' f'http://{host_port[0]}:{host_port[1]}')) - app.run(host=host_and_port[0], port=host_port[1]) + app.run(host=host_port[0], port=host_port[1]) except gaierror: print('Detected no active Internet connection.') print('Overriding to use default IP and port configuration.') From 9f1a6ce0f542fd8d9190d26e049424caf97362a9 Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Mon, 9 May 2022 12:48:16 -0400 Subject: [PATCH 4/5] Report bind errors on port attempted to bind and not default, for #763 --- ipwb/replay.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipwb/replay.py b/ipwb/replay.py index c7ece0ea..512ebd88 100755 --- a/ipwb/replay.py +++ b/ipwb/replay.py @@ -1073,7 +1073,7 @@ def start(cdxj_file_path, proxy=None, host=IPWBREPLAY_HOST, port=IPWBREPLAY_PORT print('Overriding to use default IP and port configuration.') app.run() except socketerror: - print(f'Address {IPWBREPLAY_HOST}:{IPWBREPLAY_PORT} already in use!') + print(f'Address {host_port[0]}:{host_port[1]} already in use!') sys.exit() From 81ae2622a261bca6b3843e48bb8ff99e85250a41 Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Mon, 9 May 2022 13:02:37 -0400 Subject: [PATCH 5/5] Rv to using loopback per @ibnesayeed --- ipwb/replay.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipwb/replay.py b/ipwb/replay.py index 512ebd88..8abd1295 100755 --- a/ipwb/replay.py +++ b/ipwb/replay.py @@ -1067,7 +1067,8 @@ def start(cdxj_file_path, proxy=None, host=IPWBREPLAY_HOST, port=IPWBREPLAY_PORT print((f'IPWB replay started on ' f'http://{host_port[0]}:{host_port[1]}')) - app.run(host=host_port[0], port=host_port[1]) + # Use loopback to make available on all interfaces + app.run(host='0.0.0.0', port=host_port[1]) except gaierror: print('Detected no active Internet connection.') print('Overriding to use default IP and port configuration.')