Commits

Josh VanderLinden committed 9d17ebb

Adding SSH_PORT and updating documentation

Comments (0)

Files changed (4)

 # Maintainer: Josh VanderLinden <arch@cloudlery.com>
 pkgname=autotunnel
-pkgver=0.3.3
+pkgver=0.3.4
 pkgrel=1
 pkgdesc="Easily create tunnels, reverse tunnels, and SOCKS proxies"
 arch=('any')
 :Author: Josh VanderLinden <arch@cloudlery.com>
 :Date:   2012-10-20
 :Copyright: Public Domain
-:Version: 0.3.3
+:Version: 0.3.4
 :Manual section: 1
 :Manual group: System Tools
 
 
 One interesting option offered by ``autotunnel`` is that of profiles. You may
 have multiple profiles of tunnels, each to different systems with different
-settings. All profiles should be saved in ``/etc/autotunnel.d`` as ``.conf``
-files. For example, the default profile is ``/etc/autotunnel.d/default.conf``.
+settings.
 
 There are two ways to call ``autotunnel``:
 
   will be killed.
 
 [profile]
-  The name of the profile to launch. If omitted, the default profile will be
-  used.
+  The name of the profile to launch or kill. If omitted, the default profile
+  will be used.
+
+Tunnel Profiles
+===============
+
+``autotunnel`` allows you to setup tunnels to different remote systems by using
+profiles. Profiles live in ``/etc/autotunnel.d``, and must have the extension
+``.conf``. The ``default`` profile is ``/etc/autotunnel.d/default.conf``. To
+create another profile, simply copy the default profile or create a new a new
+file with the following settings::
+
+    cp /etc/autotunnel.d/default.conf /etc/autotunnel.d/new-profile.conf
+
+There are a few configuration values that you'll be particularly interested in.
+
+* ``USER``: This is the username you wish to login as on the remote system.
+* ``HOST``: This is the hostname or IP of the remote system.
+* ``SSH_PORT``: This is the port that you use to connect to SSH on the remote
+  system. Defaults to ``22``.
+* ``SOCKS_PORT``: This is the port to establish a SOCKS proxy on. If set to
+  ``0``, no SOCKS proxy will be established.
+* ``TUNNELS``: This is a list of tunnels that will allow you access ports on
+  the remote system via ports on your local system. See the next section for
+  details.
+* ``REVERSE``: This is a list of reverse tunnels that will allow you to access
+  ports on your local system via ports on the remote system. See the next
+  section for details.
+* ``AUTOSSH_PORT``: This is the port that is used to determine when tunnels are
+  active and when they need to be re-established.
 
 If you're using multiple profiles, be sure to update the ``AUTOSSH_PORT`` value
 in each profile so there's no conflict. This is the port that is used to
 determine if a profile is already running or not. If two profiles have the same
 ``AUTOSSH_PORT``, only one of the two profiles may be running at one time.
 
-Start Tunnels Automatically At Boot
-===================================
-
-It's very important that you setup pre-shared key (PSK) authentication between
-your local system and the remote systems you plan to establish tunnels with if
-you want the tunnels to activate at boot time. You'll want to setup PSK
-authentication for your local ``root`` user to the remote system(s).
-Alternatively, you may edit the ``systemd`` unit files or ``supervisord``
-configuration files to launch the tunnels as a user of your choice.
-
-Setting up pre-shared key authentication is easy to do, and the Internet will
-be of much help to you if you're unfamiliar with it. However, I'll give a quick
-overview. As root, type this command::
-
-    ssh-keygen
-
-Accept all defaults. Now copy your public key to the remote host. Again, as
-root, run this command::
-
-    ssh-copy-id remote_user@remote_host
-
-Obviously, replace ``remote_user`` and ``remote_host`` with the appropriate
-information. Then enter the password for ``remote_user`` on ``remote_host``. If
-all went well, you should now be able to SSH into ``remote_host`` as
-``remote_user`` without entering a password. If not, Google is your friend.
-
-systemd
--------
-
-You have two options for starting the tunnels automatically at boot time. The
-first, and recommended solution, is to use ``systemd``. All you need to do is
-run the following command as root, and the tunnels defined in your default
-profile will be established the next time you reboot.
-
-::
-
-    systemctl enable autotunnel
-
-If you wish to have a specific tunnel profile launch at boot time, simply use
-the template unit file::
-
-    systemctl enable autotunnel@profile
-
-supervisord
------------
-
-If you're using ``supervisord``, you should be able to just copy or symlink the
-default configuration to your ``/etc/supervisor.d`` directory::
-
-    cp /etc/autotunnel.d/autotunnel.ini /etc/supervisor.d/
-
-If you wish for other profiles to be launched automatically, copy this file and
-replace this line::
-
-    command=/usr/local/bin/autotunnel default
-
-With::
-
-    command=/usr/local/bin/autotunnel specific-profile
-
 About Tunneling
 ===============
 
 
 To establish a SOCKS proxy, configure your profile's ``SOCKS_PORT`` to
 something greater than 0. After that, it's just a matter of configuring your
-computer or browser to use the SOCKS proxy. Each WM and browser will have its
-own configuration. Another Google assignment for you!
+computer or browser to use the SOCKS proxy. Each window manager and browser
+will have its own configuration. Another Google assignment for you!
+
+Start Tunnels Automatically At Boot
+===================================
+
+It's very important that you setup pre-shared key (PSK) authentication between
+your local system and the remote systems you plan to establish tunnels with if
+you want the tunnels to activate at boot time. You'll want to setup PSK
+authentication for your local ``root`` user to the remote system(s).
+Alternatively, you may edit the ``systemd`` unit files or ``supervisord``
+configuration files to launch the tunnels as a user of your choice.
+
+Setting up pre-shared key authentication is easy to do, and the Internet will
+be of much help to you if you're unfamiliar with it. However, I'll give a quick
+overview. As root, type this command::
+
+    ssh-keygen
+
+Accept all defaults. Now copy your public key to the remote host. Again, as
+root, run this command::
+
+    ssh-copy-id remote_user@remote_host
+
+Obviously, replace ``remote_user`` and ``remote_host`` with the appropriate
+information. Then enter the password for ``remote_user`` on ``remote_host``. If
+all went well, you should now be able to SSH into ``remote_host`` as
+``remote_user`` without entering a password. If not, Google is your friend.
+
+systemd
+-------
+
+You have two options for starting the tunnels automatically at boot time. The
+first, and recommended solution, is to use ``systemd``. All you need to do is
+run the following command as root, and the tunnels defined in your default
+profile will be established the next time you reboot.
+
+::
+
+    systemctl enable autotunnel
+
+If you wish to have a specific tunnel profile launch at boot time, simply use
+the template unit file::
+
+    systemctl enable autotunnel@profile
+
+supervisord
+-----------
+
+If you're using ``supervisord``, you should be able to just copy or symlink the
+default configuration to your ``/etc/supervisor.d`` directory::
+
+    cp /etc/autotunnel.d/autotunnel.ini /etc/supervisor.d/
+
+If you wish for other profiles to be launched automatically, copy this file and
+replace this line::
+
+    command=/usr/local/bin/autotunnel default
+
+With::
+
+    command=/usr/local/bin/autotunnel specific-profile
+
+Downloading
+===========
+
+Official downloads live on BitBucket at
+https://bitbucket.org/codekoala/autotunnel/downloads and in `Arch Linux`_'s
+`AUR`_. While this project was built for and tested on `Arch Linux`_, it is
+just a bunch of bash scripting on top of ``autossh``. You should be able to run
+this anywhere bash and autossh run.
+
+Reporting Bugs
+==============
+
+Please report bugs on the official issue tracker at
+https://bitbucket.org/codekoala/autotunnel/issues
+
+.. _Arch Linux: http://www.archlinux.org/
+.. _AUR: https://aur.archlinux.org/packages.php?O=0&K=autotunnel&do_Search=Go
 #!/bin/bash
 
+#
+# Read in the specified profile. The first argument is the profile name. If no
+# profile is specified, use the default profile.
+#
 get_config() {
   CONFIG=$1
   if [[ -z ${CONFIG} ]]; then
     CONFIG=default
   fi
 
+  # make sure the profile exists
   CFGFILE=/etc/autotunnel.d/${CONFIG}.conf
   [[ ! -f ${CFGFILE} ]] && echo "Invalid configuration file ${CFGFILE}" && exit 1
 
   source ${CFGFILE}
 }
 
+#
+# See if we need to kill an existing set of tunnels. This is triggered when
+# `autotunnel` is called with `-k` as the first argument. The second argument
+# is taken as the profile name. If no profile name is specified, the default
+# profile is used.
+#
 if [[ "$1" == "-k" ]]; then
   # kill mode
   get_config $2
   DEBUG=$2
 fi
 
+# Make sure the profile has tunnels or a SOCKS proxy configured
 if [[ -z ${TUNNELS} ]] && [[ -z ${REVERSE} ]] && [[ ${SOCKS_PORT} -eq 0 ]]; then
   echo "Nothing to do; aborting"
   exit 2
 fi
 
+# Establish the SOCKS proxy, if necessary
 if [[ ${SOCKS_PORT} -gt 0 ]]; then
   DO_SOCKS="-D ${SOCKS_PORT}"
 else
   DO_SOCKS=""
 fi
 
-CMD="autossh -M ${AUTOSSH_PORT} -NT ${USER}@${HOST} ${DO_SOCKS}"
+# Set the default SSH port
+if [[ -z ${SSH_PORT} ]]; then
+  SSH_PORT=22
+fi
+
+# Setup the command
+CMD="autossh -M ${AUTOSSH_PORT} -NT ${USER}@${HOST} -p ${SSH_PORT} ${DO_SOCKS}"
+
+# add normal tunnels
 for t in ${TUNNELS[@]}; do
     CMD="${CMD} -L ${t}"
 done
 
+# add reverse tunnels
 for rt in ${REVERSE[@]}; do
     CMD="${CMD} -R ${rt}"
 done
 
 HOST=yourhost.com
 
+# The port that SSH is listening on for connections
+
+SSH_PORT=22
+
 # Set to some other port, such as 8080, if you wish to setup a SOCKS proxy as
 # well. This would allow you to access the Internet via the remote $HOST.