diff options
Diffstat (limited to 'bin/proxy.sh')
| -rwxr-xr-x | bin/proxy.sh | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/bin/proxy.sh b/bin/proxy.sh new file mode 100755 index 0000000..a67c873 --- /dev/null +++ b/bin/proxy.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# opens a ssh tunnel and starts a new firefox instance +# configure your firefox profil to use the ssh tunnel + +user=$USER +host=$(hostname) +port=9999 + +url=$user@$host + +while [ $# -ne 0 ]; do + case "$1" in + -u|--url) + if [ "x$2" = "x" ]; then + echo "$1 requires an argument. Abort." 1>&2 + exit 1 + else + url="$2" + fi + shift + shift + ;; + -h|--host) + if [ "x$2" = "x" ]; then + echo "$1 requires an argument. Abort." 1>&2 + exit 1 + else + host="$2" + fi + shift + shift + ;; + -p|--port) + if [ "x$2" = "x" ]; then + echo "$1 requires an argument. Abort." 1>&2 + exit 1 + else + port="$2" + fi + shift + shift + ;; + *) + echo "Usage: '$(basename $0) [-u HOST] [-p PORT]'" + echo "Default connection is set to $url:$port" + exit 1 + esac +done + + +if [ "x$host" = x ]; then + echo "No host given. Abort." 1>&2 + exit 1 +fi + +if [ "x$port" = x ]; then + echo "No pott given. Abort." 1>&2 + exit 1 +fi + +if [ x$(netstat -tulpen 2>/dev/null | grep 127.0.0.1:$port | head -1 | cut -d "/" -f2) = "xssh" ]; then + echo "Using existing ssh tunnel." +else + nohup ssh -f -N $url -D $port >>/tmp/nohub.ssh$port.log 2>&1 & + if [ $? -ne 0 ]; then + echo "Failed to create the ssh tunnel. Read /tmp/nohub.ssh$port.log for more information." + exit 1 + fi +fi + +nohup firefox -no-remote -P proxy >>/tmp/nohub.fx.log 2>&1 & +if [ $? -ne 0 ]; then + echo "Failed to start Firefox. Read /tmp/nohub.fx.log for more information." + exit 1 +fi + +echo "Proxying all traffic through '$url:$port'." +exit 0 |
