Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host flag to replay #766

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ipwb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ 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.')
port = args.port

# 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 "
Expand Down Expand Up @@ -138,12 +143,18 @@ def check_args(args_in):
help='Proxy URL',
metavar='<host:port>',
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.set_defaults(func=check_args_replay,
onError=replay_parser.print_help)

Expand Down
8 changes: 4 additions & 4 deletions ipwb/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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_port[0], port=host_port[1])
machawk1 marked this conversation as resolved.
Show resolved Hide resolved
except gaierror:
print('Detected no active Internet connection.')
print('Overriding to use default IP and port configuration.')
Expand Down
2 changes: 1 addition & 1 deletion ipwb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0.0.0.0 is a "listen to all interfaces" address, it can't be resolved from the client side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibnesayeed I agree with your suggestion here. In Windows, localhost seems to resolve by default but not 0.0.0.0. Can you comment on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want host parameter to be customizable, then add a special case to see if it is set to 0.0.0.0 then for all URI rewriting and FQDN URI purposes use localhost (or the value in the proxy parameter).


(IPWBREPLAY_HOST, IPWBREPLAY_PORT) = IPWBREPLAY_ADDRESS.split(':')
IPWBREPLAY_PORT = int(IPWBREPLAY_PORT)
Expand Down