Skip to content

Commit 571b484

Browse files
committed
Merge branch 'feature/improvements'
2 parents db6daf0 + 9fe8d1c commit 571b484

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
### Environment variables
1212

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

1519
### Docker
1620

docker-compose.example.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ services:
55
image: alebabai/ssh-proxy:latest
66
build: .
77
environment:
8-
ADDRESS: "nginx:80"
8+
ADDRESSES: |-
9+
nginx:80
910
volumes:
1011
- ./tmp:/tmp/ssh-proxy
1112
networks:

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ services:
55
image: alebabai/ssh-proxy:latest
66
build: .
77
environment:
8-
ADDRESS: "localhost:80"
8+
ADDRESSES: |-
9+
localhost:80
910
volumes:
1011
- ./tmp:/tmp/ssh-proxy
1112
networks:

rootfs/entrypoint.sh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
#!/bin/bash
22

33
function open_ssh_tunnel {
4-
local timestamp=`date +%s`
4+
local timestamp=$(date +%s)
55

66
local tunnel_host=${SSH_TUNNEL_HOST:-"serveo.net"}
7-
local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp}
87
local tunnel_port=${SSH_TUNNEL_PORT:-"443"}
8+
local tunnel_prefix=${SSH_TUNNEL_PREFIX:-${timestamp}}
99
local tunnel_bindings=()
1010
local tunnel_urls=()
1111

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

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

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

0 commit comments

Comments
 (0)