Skip to content

Commit

Permalink
Merge branch 'feature/improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
alebabai committed Aug 13, 2019
2 parents db6daf0 + 9fe8d1c commit 571b484
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

### Environment variables

- `ADDRESS` - _provide one or more `HOST:PORT` pairs separated by space for services to be exposed_
- `ADDRESSES` - _provide one or more `HOST:PORT` pairs separated by space or new line for services to be exposed_
- `OUTPUT_FILE` - _prefix of the exposed url (default `$timestamp`)_
- `SSH_TUNNEL_HOST` - _host of the service that will be used as ssh-server (default `serveo.net`)_
- `SSH_TUNNEL_PORT` - _port of the service that will be used as ssh-server (default `443`)_
- `SSH_TUNNEL_PREFIX` - _name of the file with exposed urls (default `/tmp/ssh-proxy/output.txt`)_

### Docker

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
image: alebabai/ssh-proxy:latest
build: .
environment:
ADDRESS: "nginx:80"
ADDRESSES: |-
nginx:80
volumes:
- ./tmp:/tmp/ssh-proxy
networks:
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ services:
image: alebabai/ssh-proxy:latest
build: .
environment:
ADDRESS: "localhost:80"
ADDRESSES: |-
localhost:80
volumes:
- ./tmp:/tmp/ssh-proxy
networks:
Expand Down
25 changes: 13 additions & 12 deletions rootfs/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
#!/bin/bash

function open_ssh_tunnel {
local timestamp=`date +%s`
local timestamp=$(date +%s)

local tunnel_host=${SSH_TUNNEL_HOST:-"serveo.net"}
local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp}
local tunnel_port=${SSH_TUNNEL_PORT:-"443"}
local tunnel_prefix=${SSH_TUNNEL_PREFIX:-${timestamp}}
local tunnel_bindings=()
local tunnel_urls=()

for address in ${ADDRESS[@]}
for address in ${ADDRESSES[@]}
do
local remote_hostname=$(echo $address | cut -d ':' -f 1)
local tunnel_address=$tunnel_prefix-$remote_hostname:$tunnel_port
tunnel_bindings+=("$tunnel_address:$address")
tunnel_urls+=("https://$tunnel_prefix-$remote_hostname.$tunnel_host")
local remote_hostname=$(echo ${address} | cut -d ':' -f 1)
local tunnel_address=${tunnel_prefix}-${remote_hostname}:${tunnel_port}
tunnel_bindings+=("${tunnel_address}:${address}")
tunnel_urls+=("https://${tunnel_prefix}-${remote_hostname}.${tunnel_host}")
done

if [ -z "$tunnel_bindings" ]; then
if [ -z "${tunnel_bindings}" ]; then
exit 1
else
local output_file=${OUTPUT_FILE:-"/tmp/ssh-proxy/output.txt"}
printf "%s\n" ${tunnel_urls[@]} > $output_file
mkdir -p $(dirname ${output_file})
printf "%s\n" ${tunnel_urls[@]} > ${output_file}

local cmd="ssh -T -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $SSH_ARGS $(printf " -R %s" ${tunnel_bindings[@]}) $tunnel_host"
echo $cmd
exec $cmd
local cmd="ssh -T -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${SSH_ARGS} $(printf " -R %s" ${tunnel_bindings[@]}) ${tunnel_host}"
echo ${cmd}
exec ${cmd}
fi
}

Expand Down

0 comments on commit 571b484

Please sign in to comment.