mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-21 15:33:23 +01:00
windows: add --remote-shell option to select cmd/powershell
This commit is contained in:
parent
dff6950c4c
commit
bac2a6b0c7
@ -181,6 +181,11 @@ Options
|
||||
in a non-standard location or you want to provide extra
|
||||
options to the ssh command, for example, ``-e 'ssh -v'``.
|
||||
|
||||
.. option:: --remote-shell
|
||||
|
||||
For Windows targets, specify configured remote shell program alternative to defacto posix shell.
|
||||
It would be either ``cmd`` or ``powershell`` unless something like git-bash is in use.
|
||||
|
||||
.. option:: --no-cmd-delimiter
|
||||
|
||||
Do not add a double dash (--) delimiter before invoking Python on
|
||||
|
@ -211,8 +211,8 @@ class FirewallClient:
|
||||
self.auto_nets = []
|
||||
|
||||
argv0 = sys.argv[0]
|
||||
# argv0 is either be a normal python file or an executable.
|
||||
# After installed as a package, sshuttle command points to an .exe in Windows and python shebang script elsewhere.
|
||||
# argv0 is either be a normal Python file or an executable.
|
||||
# After installed as a package, sshuttle command points to an .exe in Windows and Python shebang script elsewhere.
|
||||
argvbase = (([sys.executable, sys.argv[0]] if argv0.endswith('.py') else [argv0]) +
|
||||
['-v'] * (helpers.verbose or 0) +
|
||||
['--method', method_name] +
|
||||
@ -591,7 +591,7 @@ def ondns(listener, method, mux, handlers):
|
||||
def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
||||
python, latency_control, latency_buffer_size,
|
||||
dns_listener, seed_hosts, auto_hosts, auto_nets, daemon,
|
||||
to_nameserver, add_cmd_delimiter):
|
||||
to_nameserver, add_cmd_delimiter, remote_shell):
|
||||
|
||||
helpers.logprefix = 'c : '
|
||||
debug1('Starting client with Python version %s'
|
||||
@ -607,6 +607,7 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
||||
ssh_cmd, remotename, python,
|
||||
stderr=ssyslog._p and ssyslog._p.stdin,
|
||||
add_cmd_delimiter=add_cmd_delimiter,
|
||||
remote_shell=remote_shell,
|
||||
options=dict(latency_control=latency_control,
|
||||
latency_buffer_size=latency_buffer_size,
|
||||
auto_hosts=auto_hosts,
|
||||
@ -809,7 +810,7 @@ def main(listenip_v6, listenip_v4,
|
||||
latency_buffer_size, dns, nslist,
|
||||
method_name, seed_hosts, auto_hosts, auto_nets,
|
||||
subnets_include, subnets_exclude, daemon, to_nameserver, pidfile,
|
||||
user, group, sudo_pythonpath, add_cmd_delimiter, tmark):
|
||||
user, group, sudo_pythonpath, add_cmd_delimiter, remote_shell, tmark):
|
||||
|
||||
if not remotename:
|
||||
raise Fatal("You must use -r/--remote to specify a remote "
|
||||
@ -1158,7 +1159,7 @@ def main(listenip_v6, listenip_v4,
|
||||
return _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
|
||||
python, latency_control, latency_buffer_size,
|
||||
dns_listener, seed_hosts, auto_hosts, auto_nets,
|
||||
daemon, to_nameserver, add_cmd_delimiter)
|
||||
daemon, to_nameserver, add_cmd_delimiter, remote_shell)
|
||||
finally:
|
||||
try:
|
||||
if daemon:
|
||||
|
@ -116,6 +116,7 @@ def main():
|
||||
opt.group,
|
||||
opt.sudo_pythonpath,
|
||||
opt.add_cmd_delimiter,
|
||||
opt.remote_shell,
|
||||
opt.tmark)
|
||||
|
||||
if return_code == 0:
|
||||
|
@ -315,6 +315,14 @@ parser.add_argument(
|
||||
do not add a double dash before the python command
|
||||
"""
|
||||
)
|
||||
parser.add_argument(
|
||||
"--remote-shell",
|
||||
metavar="PROGRAM",
|
||||
help="""
|
||||
alternate remote shell program instead of defacto posix shell.
|
||||
For Windows targets it would be either `cmd` or `powershell` unless something like git-bash is in use.
|
||||
"""
|
||||
)
|
||||
parser.add_argument(
|
||||
"--seed-hosts",
|
||||
metavar="HOSTNAME[,HOSTNAME]",
|
||||
|
@ -84,7 +84,7 @@ def parse_hostport(rhostport):
|
||||
return username, password, port, host
|
||||
|
||||
|
||||
def connect(ssh_cmd, rhostport, python, stderr, add_cmd_delimiter, options):
|
||||
def connect(ssh_cmd, rhostport, python, stderr, add_cmd_delimiter, remote_shell, options):
|
||||
username, password, port, host = parse_hostport(rhostport)
|
||||
if username:
|
||||
rhost = "{}@{}".format(username, host)
|
||||
@ -134,6 +134,13 @@ def connect(ssh_cmd, rhostport, python, stderr, add_cmd_delimiter, options):
|
||||
portl = ["-p", str(port)]
|
||||
else:
|
||||
portl = []
|
||||
if remote_shell == "cmd":
|
||||
pycmd = '"%s" -c "%s"' % (python or 'python', pyscript)
|
||||
elif remote_shell == "powershell":
|
||||
for c in ('\'', ' ', ';', '(', ')', ','):
|
||||
pyscript = pyscript.replace(c, '`' + c)
|
||||
pycmd = '%s -c %s' % (python or 'python', pyscript)
|
||||
else: # posix shell expected
|
||||
if python:
|
||||
pycmd = '"%s" -c "%s"' % (python, pyscript)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user