Skip to content

Commit

Permalink
Pass local and remote addresses to exec: command
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Oct 4, 2019
1 parent 761f19e commit 28e4309
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.13 (2019-10-04)

- Pass local and remote addresses to "exec:" commands.
- Don't error for destination addresses of less than 5 characters.

# v0.12 (2019-08-18)

- Allow destination address to come from a command.
Expand Down
5 changes: 4 additions & 1 deletion README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ to avoid having to use additional port numbers:
- "exec:/full/path/to/command" (destination)

Useful to get the destination address dynamically from a command.
It should print "host:port" on stdout and return zero.
The command will receive the following arguments:
- local address (host:port)
- remote address (host:port)
The command should print the destination "host:port" on stdout and return zero.
If the command exits non-zero the status and stderr of the command
will be printed to stdout and the connection will be dropped.

Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *Service) handleConnection(src *net.TCPConn, dst string, done chan bool)
if len(dst) > 5 && dst[0:6] == "exec:/" {
var stdout, stderr bytes.Buffer
path := dst[5:len(dst)]
cmd := exec.Command(path)
cmd := exec.Command(path, src.LocalAddr().String(), src.RemoteAddr().String())
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
Expand Down
9 changes: 8 additions & 1 deletion test/dest-addr
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#!/bin/bash

echo "localhost:${PROXY_PORT:-62000}"
# use same ip as request
host="${1%:*}"
if [[ -n "$host" ]]; then
echo "$host:${PROXY_PORT:-62000}"
else
echo "args: ($1) ($2)" >&2
exit 1
fi

0 comments on commit 28e4309

Please sign in to comment.