summaryrefslogtreecommitdiff
path: root/bin/proxy.sh
diff options
context:
space:
mode:
authorHorus32014-07-23 13:57:01 +0200
committerHorus32014-07-23 13:57:01 +0200
commit0ad31ff4b26686c7d3f851b51c1c5f885fda8730 (patch)
tree1c519a465f50e2fc3595f300d573487ede4cfbe1 /bin/proxy.sh
parent363f7b89a7d38ef4fc99f81780b5c2d08fa12203 (diff)
downloaddotfiles-0ad31ff4b26686c7d3f851b51c1c5f885fda8730.tar.gz
added proxy script
Diffstat (limited to 'bin/proxy.sh')
-rwxr-xr-xbin/proxy.sh78
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