This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: add tunneling script for access via SSH
License: MIT Signed-off-by: Lars Gierth <[email protected]>
- Loading branch information
Lars Gierth
committed
Nov 9, 2015
1 parent
e80ea37
commit 3f54b4b
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/sh | ||
|
||
[email protected] | ||
target=metrics.i.ipfs.io:80 | ||
localport=8080 | ||
|
||
usage() { | ||
echo "usage: $0 [<proxy>] [<target>] [<localport>]" | ||
echo "proxy through to a target " | ||
exit 1 | ||
} | ||
|
||
die() { | ||
echo "error: $@" | ||
exit 1 | ||
} | ||
|
||
if [ $# -ge 1 ]; then | ||
proxy="$1" | ||
fi | ||
|
||
if [ $# -ge 2 ]; then | ||
target="$2" | ||
fi | ||
|
||
if [ $# -ge 3 ]; then | ||
localport="$3" | ||
fi | ||
|
||
# set up local url | ||
localurl="http://localhost:$localport" | ||
|
||
# setup proxy | ||
echo "setting up proxy through $proxy" | ||
ssh "$proxy" -N -L "$localport:$target" & | ||
sid="$!" | ||
|
||
kill -0 "$!" || die "failed to log into $proxy" | ||
|
||
cleanup() { | ||
echo "stopping..." | ||
kill "$sid" | ||
exit | ||
} | ||
|
||
trap cleanup INT TERM | ||
|
||
# use proxy | ||
echo "proxying $localurl -> $proxy -> $target" | ||
|
||
# open | ||
echo "open $localurl" | ||
open "$localurl" | ||
|
||
# wait forever | ||
echo "enter ^C to stop" | ||
tail -f /dev/null |